Sunday, January 29, 2017

Running Oracle in a Docker Container - Part 2

In the last post I showed how to get started with Docker. This post talks about making changes stick, and creating a repository to share your containers.

So, you have a container, made some changes, and want to keep all your hard work. Unless you commit the changes, the next time you open the container it will lose them.



For example, creating a user:

 

I created the user 'andy' and set a password, and switched to the user, then created a file.

However, if I exit and restart the container, the change is lost:

 

When you exit a container, docker creates an entry in a process list.
In order to commit the changes, you need to identify the process id and save it.

The command for this is ps –a:

 


Restart the container add the user:


Exit from the container and find the last image ID. 

 

Commit the change to this container:

 

Note I've added a tag to the end of the name of the container – this is how you manage versions. So I have a container that is unchanged, and I've created one with a tag called 'latest' – this is the one with the change.

 

Tip: After a while there will be loads of entries in the 'ps –a' list, use this to clean them out:
docker rm $(docker ps -qa --no-trunc --filter "status=exited")



So now I start the new container using the tag, and the changes will be there:

 

All the containers are kept on your local machine, but if you create a repository you can store them there and share them with others.

You can create a cloud repository in Docker for free.




Create an id








A verification mail will be sent, click on the link, then sign in.






After logging in, ignore most of the page, but at the top left click on 'Repositories':



 


It will be empty, so create one:



 




Give it a name, the same as the name of your container, and click 'create'