There are two concepts that I believe needs explaining before we continue. Docker images and docker containers. A container is a running process managed by docker that is based on a docker image. There are two ways to create an image:
- You specify a
Dockerfile
with all dependencies and build it using docker build
. Then it is saved in your local registry (or you can push it to a central location)
- You can start a container based on an image, make modifications in that container and then
commit
the changes.
Containers are simply processes that are running they are always based on an image. Note that a container can never change an image (unless you commit). IMO the Dockerfile
approach is far superior.
So, back to the original question. The VOLUME
directive in the Dockerfile
simply creates a mounting point for a container, it does not actually mount anything from the host filesystem to the container filesystem. In order to actually mount a folder from the host the -v
flag must be provided when running the container.
docker run -v /host/path:/container/path ...
This creates a shared folder between the host and the container and the data survives even after the container has been stopped, removed or crashed.
- I have to build the new container from the updated mysql image
Yes, if you have updated something in the Dockerfile
you will have to build a new image (not container) and deploy the image to your production environment. Then, you can start a container using docker run
based on the newly built image.
- I need to delete the old conatiner so i will stop that and delete it.
Yes, you will have to stop the old container and then delete it. After that you can start your new container using the same name but this time it is based on a new image. The deletion of the container is needed since it is a named container and you will get a name conflict if you start a new container with the same name (i.e. the container is started with the --name
option for docker run
). If the container had not been named, removing the old container could have been skipped.
- Then i need to create the new mysql container with same name so that other webserver using the database can use it.
Yes, since you are probably using container linking to achieve this.
Resources: