linuxdockervirtualizationlxc

docker run container, how to rerun


I build container with:

docker build -f Dockerfile.xyz -t dave/xyz .

after that I run docker with:

docker run -it \
--env='LDAP_USER=uid=bot_for_git,ou=bots,dc=company,dc=org' \
--env='LDAP_PASS=' --volume=/srv/docker/xyz/data1:/data \
-p 8010:8010 -p 9989:9989 dave/xyz

and verified that's all ok.

what is next?

My guess, that I should run docker ps, take container id from there, and to run container with the same preferences (environment, port mapping, volumes mapping) I should run:

docker start -a container_id

am I right?

And what about rebuilding image, if change Dockerfile.xyz and rebuild dave/xyz, does container with container_id get update automatically, or I should repeat docker run -it step?


Solution

  • docker build [...] creates an image. You can see your images with docker images. You may give that image a specific name with the --tag=[...] option:

        docker build --tag="superuser/bestimage:latest" .
    

    docker run [...] <imageId> takes that image and starts a container. You can see active containers with docker ps (all with docker ps -a). If you used the tag above, docker run -it superuser/bestimage:latest may be used.

    When you rebuild an image, a new image with a new id is created. You may see that through docker images.

    does container with container_id get update automatically

    No. In order to update your container, you must first remove the container with docker kill <id> and then start a new one with docker run -it <newID>.