An Image is a snapshot of one or multiple Containers
It can be a name, the container full id or just a the begining string from container id long enough to be different from other containers on the machine
The Swarm mode let us use multiple machines to create one container
For each service you can define one or multiple networks and at the end of the docker-compose file you tell every networks of your project. Saying that a service belongs to a specific network enable them to access services inside the specified networks
If a service needs an other one to be launched first, it has to be said in the depends_on section
The Dockerfile is basically the file that "parse" my local version of the code to the future folder on the server where my code will be executed. It contains instruction to setting up the environment.
Note :
The WORDIR command only change the working directory for RUN commands, otherwise, ADD, COPY and so on are not impacted.
It's the file containing containers of my project (if I'm using multiple containers) such as NodeJS, PHP, MongoDB, MySQL, Python ... It's will link them together to create our final Docker Image
It's not necessary to run an image nor a container, it provides an other IP adress thant the default 0.0.0.0
For Mac
docker-machine create --driver virtualbox [ name of the machine ] # If there is no machine on your system, call your first one default
docker-machine env [ name of the machine]
eval "$(docker-machine env default)" # To connect your shell to the new machine
docker-machine ls
docker-compose build
docker start [ container ]
docker stop [ container ]
docker rm [ container / list of containers ]
docker ps # With -a you can see all containers, without, just actives ones
docker images
docker rmi [ image ]
docker rmi $(docker images -a -q)
docker volume rm $(docker volume ls -q)
docker rm $(docker ps -a -q)
docker run [ image ] # Run a container
docker run -it [ image ] [ command ] # Run and launch a command inside the container in interactive mode; using 'bin/bash' it opens a shell inside
docker run --name [ name ] [ image ] # Run and name a container
docker run -e [VARIABLE_NAME]=[KEY] [ image ] # Run and set a environment variable to the container
docker run -d [ image ] # Run in detacher mode -> the terminal won't be connected to the container -> no commands, no prompt ...
docker run -P [ image ] # Run and all the exposed ports in the container will be published to random ports of the host
docker run -p [port on my physical machine]:[port inside the container] # Run and map the port on my physical machine to the port inside the container
docker-compose rm
# Only running containers
docker ps
# All containers
docker ps -a
docker images
docker run [ image name ][optional ":"tag name]
docker rename [ previous name ] [ new name ]
docker-compose up
docker-machine start [ name of machine ]
docker-machine ip [ name of the image ]
# Delete an image
docker rmi [ name of the image ]
# Delete all images
docker rmi $(docker images -q)
docker rm [ name or ID of the container ]
docker login
docker tag [ image ] [ Docker ID ]/[ image ][:tag]
docker push [ Docker ID ]/[ image ][:tag]
Note :
The tag is what is going to be visible in the Docker Cloud to identify your commit
# If the container is running
docker exec -it [optional --name 'name I want to give'] [optional -u 'user' to launch the command like a specific user] [ name of container ] [ the command I want to launch ]
# NB : If we enter exit to leave the container, it will still be running in the background
# OR
# If the container is not running
docker run -it [optional --name 'name I want to give'] [ id of the container ] [ the command I want to launch ]
# NB : If we enter exit to leave the container, it will be stopped as well
With the command 'bash' we open a shell inside the container, and we can browse, edit, install stuffs ...
docker start [ name or ID of the container ]
For example if we want to launch a service
docker stop [ name or ID of the container ]
# You can also restart it
docker restart [ name or ID of the container ]
docker commit [ container name or ID ] [ how I want my image to be named ]
docker cp [location] [destination] # Path within a container = [container]:[path of the file]
docker run -td --name [name I want to give] -p [ports I\'m exposing] [ name of the image ]
docker port [ container ]
docker run -it --name [name I want to give] -v [absolute path of what I want to mount]:[absolute path where I want to mount it in the container]
If we mount a volume to a container and we delete this container, the volume will still exists, so we can create an other container and mounting the volume to it, this way we make persistance
# Listing all volumes
docker volume ls
# Mounting a volume to a container
docker run -it --name [name I want to give] -v [name we want to call it]:[absolute path where I want to mount it in the container]
# Mounting the volumes from a container to an other that that they can 'exchange' datas
docker run -it --name [name I want to give] --volumes-from [container where volumes are]
docker inspect [container]
docker run -it --name [name I want to give] -e [KEY]=[VALUE] [optional -e [KEY]=[VALUE]]
# Or with a file
docker run -it --env-file [path of the file]
# If we want to change a value at the fly like passing from dev to prof
docker run -it --env-file [path of the file] -e [KEY_I_WANT_TO_CHANGE]=[NEW_VALUE]
# After being logged
docker push [ name on Docker Hub ]/[ image name ]:[ tag ]
docker pull
docker swarm init
docker stack deploy [ name of the swarm ]
docker stack deploy --compose-file [ YAML file needed for the composing ] [ name of the swarm ] # To use a compose file
docker stack services [ name of the Swarm ]
docker stack ls
docker stack rm [ name of the swarm ]
docker update --restart=no [ my-container ]
docker update --restart=unless-stopped [ my-container ]