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'

 



In this example, I've created one for Centos:



So you have a repository, but nothing in it.

Go back to your docker command line, and you can upload the container you created with the added user:


Login to the repository:



To upload, you first tag the image, then use the 'push' command:




The container is now in the cloud repository (note that it takes a while to show up – the Docker cloud is pretty slow).


However, if the push command came back with no errors, the container will be there. 


Downloading a container

Suppose you mess up your local copy. You can delete the local image(s) and pull one down from the repository.


If you try before deleting the local copy, it won't do anything because it's up to date, so delete it first:



Note the 'centos' shown here is the unchanged one without the added user. Delete it if you like.


So, now get the version you uploaded to the repository, even though the web page doesn't show it:




The image is there, and can be started:


And the changes are there:




Next time, using an Oracle database inside a container.
























No comments:

Post a Comment