This page gathers information concerning the use of Docker
Basics
- A container is an instance of an image (e.g running image)
Installation
Currently, on Linux mint, don't use the apt-get package, but the installation procedure on the Docker page. To be able to run docker as a user:sudo usermod -aG docker axelleThen unlog/relog.
Commands
- docker images: shows all existing images on your host
- docker search: to search for (public) images:
docker search --stars=10 debian
- docker pull: to download a given image:
docker pull docker/whalesay
- docker run: to run a given image (-> container):
$ docker run hello-world
- docker ps: list all running containers. If you specify docker ps -a, you'll list all containers even those which have exited.
- docker stop container: stops a container
- docker rmi: removes an image. For example:
docker rmi -f tag
- docker logs container: view logs of the container. Add -f to follow the flow of logs
- docker inspect container: view the configuration of a given image or container
What's my container id?
If you are running an interactive shell in the container, then the container id shows in the prompt:root@deffbaefb43f <- that's the container idYou can also get the id with docker ps -a.
Details
Copying a file to the container
cp thefile.txt /var/lib/docker/devicemapper/mnt/123abc/rootfs/root
Creating a data container
The following container merely creates two directories in which data will be held:docker create -v /usr/src/redmine/config -v /usr/src/redmine/files --name redmine-data redmine /bin/true
Port forwarding or redirection
In this case, the container redirects port 9000 to 8000 to the external world:$ docker run -d -p 8000:9000 ...If there are several ports to redirect, add as many -p directives. If the port should not redirected, but still open: -p 9000:9000 for example.
Running an interactive container
It's the -i option in docker run. The typical command which is very much used is:docker run -t -i container /bin/bashThe -t gets a tty. And this command will get an interactive shell in the container. You can also use:
docker exec -it container bash
Virtualize MAC address
$ docker run -d ... --mac-address="00:11:22:33:44:55" blah/blah
Launching a server automatically
When launched with "docker run", a container exits as soon as the command returns. If we want the container to remain alive, the idea is to launch the container with a command that does not return. To do so, a solution is to use "supervisord":sudo apt-get install supervisorThen in /etc/supervisor/conf.d, create a configuration file for the service to launch:
command=... autostart=true autorestart=false stderr_logfile=/var/log/blah.err.log stdout_logfile=/var/log/blah.out.logand in /etc/supervisor/supervisor.conf, add:
[supervisord] nodaemon=trueThen, you should refresh supervisor:
$ supervisorctl reread $ supervisorctl updateCheck your service runs ok:
$ supervisorctlIf not, check the logs. Then, run your docker container like:
$ docker run -d ... container /usr/bin/supervisord
Docker file
ROM debian:wheezy MAINTAINER nameThe ENTRYPOINT is to start when the container starts.RUN apt-get update COPY nginx.conf /etc/nginx/nginx.conf RUN chmod 744 /home/docker/script/service_start.sh ENTRYPOINT /home/docker/script/service_start.sh WORKDIR /home/docker
Building
docker build -t name .
Backup
To backup an image:$ docker save -o ~/container1.tar container1To restore:
$ docker load -i /container1.tarTo backup a container, the idea is to perform a commit:
$ docker commit container-id name
Interesting images
- debian