Go version (client): go1.2.1 Git commit (client): 990021a Server version: 1.0.1 Server API version: 1.12 Go version (server): go1.2.1 Git commit (server): 990021a $ docker info Containers: 0 Images: 0 Storage Driver: aufs Root Dir: /var/lib/docker/aufs Dirs: 0 Execution Driver: native-0.2 Kernel Version: 3.13.0-30-generic WARNING: No swap limit support
VIRTUAL SIZE ubuntu 14.10 58faa899733f 10 hours ago 196 MB ubuntu utopic 58faa899733f 10 hours ago 196 MB ubuntu precise ea7d6801c538 6 days ago 127.5 MB ubuntu 12.04 ea7d6801c538 6 days ago 127.5 MB ubuntu latest ef83896b7fb9 6 days ago 192.7 MB ubuntu trusty ef83896b7fb9 6 days ago 192.7 MB ubuntu 12.10 c5881f11ded9 12 days ago 172.2 MB ubuntu quantal c5881f11ded9 12 days ago 172.2 MB ubuntu raring 463ff6be4238 12 days ago 169.4 MB ubuntu 13.04 463ff6be4238 12 days ago 169.4 MB ubuntu 13.10 195eb90b5349 12 days ago 184.7 MB ubuntu saucy 195eb90b5349 12 days ago 184.7 MB ubuntu 14.04 e54ca5efa2e9 12 days ago 276.5 MB ubuntu 10.04 3db9c44f4520 10 weeks ago 183 MB ubuntu lucid 3db9c44f4520 10 weeks ago 183 MB # du -sh /var/lib/docker/aufs/ 1.6G /var/lib/docker/aufs/
VIRTUAL SIZE ubuntu 14.10 58faa899733f 10 hours ago 196 MB ubuntu utopic 58faa899733f 10 hours ago 196 MB ubuntu precise ea7d6801c538 6 days ago 127.5 MB ubuntu 12.04 ea7d6801c538 6 days ago 127.5 MB ubuntu latest ef83896b7fb9 6 days ago 192.7 MB ubuntu trusty ef83896b7fb9 6 days ago 192.7 MB ubuntu 12.10 c5881f11ded9 12 days ago 172.2 MB ubuntu quantal c5881f11ded9 12 days ago 172.2 MB ubuntu raring 463ff6be4238 12 days ago 169.4 MB ubuntu 13.04 463ff6be4238 12 days ago 169.4 MB ubuntu 13.10 195eb90b5349 12 days ago 184.7 MB ubuntu saucy 195eb90b5349 12 days ago 184.7 MB ubuntu 14.04 e54ca5efa2e9 12 days ago 276.5 MB ubuntu 10.04 3db9c44f4520 10 weeks ago 183 MB ubuntu lucid 3db9c44f4520 10 weeks ago 183 MB # du -sh /var/lib/docker/aufs/ 1.6G /var/lib/docker/aufs/ That’s 2727.5 MB
VIRTUAL SIZE ubuntu 14.10 58faa899733f 10 hours ago 196 MB ubuntu utopic 58faa899733f 10 hours ago 196 MB ubuntu precise ea7d6801c538 6 days ago 127.5 MB ubuntu 12.04 ea7d6801c538 6 days ago 127.5 MB ubuntu latest ef83896b7fb9 6 days ago 192.7 MB ubuntu trusty ef83896b7fb9 6 days ago 192.7 MB ubuntu 12.10 c5881f11ded9 12 days ago 172.2 MB ubuntu quantal c5881f11ded9 12 days ago 172.2 MB ubuntu raring 463ff6be4238 12 days ago 169.4 MB ubuntu 13.04 463ff6be4238 12 days ago 169.4 MB ubuntu 13.10 195eb90b5349 12 days ago 184.7 MB ubuntu saucy 195eb90b5349 12 days ago 184.7 MB ubuntu 14.04 e54ca5efa2e9 12 days ago 276.5 MB ubuntu 10.04 3db9c44f4520 10 weeks ago 183 MB ubuntu lucid 3db9c44f4520 10 weeks ago 183 MB # du -sh /var/lib/docker/aufs/ 1.6G /var/lib/docker/aufs/ That’s 2727.5 MB Images have alias
world! $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu 14.10 58faa899733f 10 hours ago 196 MB ubuntu utopic 58faa899733f 10 hours ago 196 MB ubuntu precise ea7d6801c538 6 days ago 127.5 MB ubuntu 12.04 ea7d6801c538 6 days ago 127.5 MB ubuntu latest ef83896b7fb9 6 days ago 192.7 MB ubuntu trusty ef83896b7fb9 6 days ago 192.7 MB ubuntu 12.10 c5881f11ded9 12 days ago 172.2 MB ubuntu quantal c5881f11ded9 12 days ago 172.2 MB ubuntu raring 463ff6be4238 12 days ago 169.4 MB ubuntu 13.04 463ff6be4238 12 days ago 169.4 MB ubuntu 13.10 195eb90b5349 12 days ago 184.7 MB ubuntu saucy 195eb90b5349 12 days ago 184.7 MB ubuntu 14.04 e54ca5efa2e9 12 days ago 276.5 MB ubuntu 10.04 3db9c44f4520 10 weeks ago 183 MB ubuntu lucid 3db9c44f4520 10 weeks ago 183 MB “echo hello world” didn’t change container’s state so no new image
world! Docker caches every command that you run in a container The container needs a foreground process to keep running $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3b2ba0029d69 ubuntu:latest /bin/echo 'Hello wor 3 seconds ago Exited (0) sharp_wozniak
world! $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3b2ba0029d69 ubuntu:latest /bin/echo 'Hello wor 3 seconds ago Exited (0) sharp_wozniak The container finished so we use -a option The container needs a foreground process to keep running Docker caches every command that you run in a container
do echo hello world; sleep 1; done" hello world hello world ... $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d82fe57ca931 ubuntu:latest /bin/sh -c 'while tr About a minute ago Up About a minute kickass_hoover We have a foreground process so the container keeps running Foreground container & Foreground process inside container
do echo hello world; sleep 1; done" hello world hello world ... $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d82fe57ca931 ubuntu:latest /bin/sh -c 'while tr About a minute ago Up About a minute kickass_hoover Manage the container with this ID This keeps running until we stop We have a foreground process so the container keeps running Foreground container & Foreground process inside container
-c "while true; do echo hello world; sleep 1; done" cffc463c6b4a8f830355c0c29434f3322c97b075e98a5081487b433c1462b8b2 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cffc463c6b4a ubuntu:latest /bin/sh -c 'while tr About a minute ago Up About a minute nostalgic_mcclintock Background container & Foreground process inside container We have a foreground process so the container keeps running
/bin/bash root@c220646d55c3:/# /bin/bash is a trick to have an fg process and a shell inside the container We have an interactive shell -i Sets STDIN when not attached too -t Opens a PTY (Pseudo TTY)
ID IMAGE COMMAND CREATED STATUS PORTS NAMES c220646d55c3 ubuntu:latest /bin/bash 16 minutes ago Exited (0) 24 seconds ago berserk_bartik Exited or running containers can be commited 773bc3dcf004120e38a0a8f1fb0036d886700bcb928cc8ce82e3d320aa38b660 $ docker commit c220646d55c3 slok/redis
ID IMAGE COMMAND CREATED STATUS PORTS NAMES c220646d55c3 ubuntu:latest /bin/bash 16 minutes ago Exited (0) 24 seconds ago berserk_bartik Exited or running containers can be commited 773bc3dcf004120e38a0a8f1fb0036d886700bcb928cc8ce82e3d320aa38b660 Container ID $ docker commit c220646d55c3 slok/redis Repository name = Image name = {USER}/{NAME}
18:51:34.756 # Warning: no config file specified, using the default config. In order to specify a config file use /usr/bin/redis-server /path/to/redis.conf _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 2.8.4 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 1 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' [1] 01 Jul 18:51:34.760 # Server started, Redis version 2.8.4 [1] 01 Jul 18:51:34.761 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. [1] 01 Jul 18:51:34.761 * The server is now ready to accept connections on port 6379
"IPAddress": "172.17.0.8", $ redis-cli -h 172.17.0.8 -p 6379 BAD! We need to expose container ports! $ docker stop fbf7a9cedd3 fbf7a9cedd3 $ docker run -d -p 16379:6379 slok/redis /usr/bin/redis-server af5989ca5600aa51ac0441ddda0e595c2fdecaa59495a02c72767956bba47794 Expose container port and map public address on port 16379 to private address 6379
"IPAddress": "172.17.0.9", $ redis-cli -h 172.17.0.9 -p 6379 172.17.0.9:6379> $ redis-cli -h 127.0.0.1 -p 16379 127.0.0.1:16379> By default no ports are exposed, we need to use -p or -P -P exposes all, -p one or more with XXXX or YYYY:XXXX format
"IPAddress": "172.17.0.9", $ redis-cli -h 172.17.0.9 -p 6379 172.17.0.9:6379> $ redis-cli -h 127.0.0.1 -p 16379 127.0.0.1:16379> Public access to mapped port Private access to container port By default no ports are exposed, we need to use -p or -P -P exposes all, -p one or more with XXXX or YYYY:XXXX format
6d4c1a61cefc4e29c69d6d2c695dd3acf4c34a8f213ad26b9442eb08d6d2f488 $ docker ps CONTAINER ID IMAGE COMMAND CREATED PORTS 6d4c1a61cefc slok/redis:latest /usr/bin/redis-serve 39 seconds ago 0.0.0.0:49153->6379/tcp Ports are published in random high number ports -P maps all exposed ports in the container* # netstat -ltnp Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 714/rpcbind tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1594/sshd tcp 0 0 0.0.0.0:39997 0.0.0.0:* LISTEN 757/rpc.statd tcp6 0 0 :::49153 :::* LISTEN 914/docker tcp6 0 0 :::111 :::* LISTEN 714/rpcbind tcp6 0 0 :::46705 :::* LISTEN 757/rpc.statd tcp6 0 0 :::22 :::* LISTEN 1594/sshd Random high number mapped port available
6d4c1a61cefc4e29c69d6d2c695dd3acf4c34a8f213ad26b9442eb08d6d2f488 $ docker ps CONTAINER ID IMAGE COMMAND CREATED PORTS 6d4c1a61cefc slok/redis:latest /usr/bin/redis-serve 39 seconds ago 0.0.0.0:49153->6379/tcp Ports are published in random high number ports -P maps all exposed ports in the container* # netstat -ltnp Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 714/rpcbind tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1594/sshd tcp 0 0 0.0.0.0:39997 0.0.0.0:* LISTEN 757/rpc.statd tcp6 0 0 :::49153 :::* LISTEN 914/docker tcp6 0 0 :::111 :::* LISTEN 714/rpcbind tcp6 0 0 :::46705 :::* LISTEN 757/rpc.statd tcp6 0 0 :::22 :::* LISTEN 1594/sshd Random high number mapped port available *Exposing ports are set in Dockerfiles We’ll see later!
Ports only accessible by containers We are using ports, but not exposed outside docker environment Don’t need to know specific ports More secure Ports shared in environment vars
slok/redis /usr/bin/redis-server 5fbba787207f4c87da20145391ec0e6c57f61c511bb00d118d05cf4a2145f5ae $ docker run ubuntu:14.04 env HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=4252df779431 $ docker run --name redis_checker --link redis:db ubuntu:14.04 env HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=44ffc20b8b67 DB_PORT=tcp://172.17.0.37:6379 DB_PORT_6379_TCP=tcp://172.17.0.37:6379 DB_PORT_6379_TCP_ADDR=172.17.0.37 DB_PORT_6379_TCP_PORT=6379 DB_PORT_6379_TCP_PROTO=tcp DB_NAME=/redis_checker/db Use env vars to connect services (and/or /etc/hosts) Use the alias in uppercase as prefix for env vars
slok/redis /usr/bin/redis-server 5fbba787207f4c87da20145391ec0e6c57f61c511bb00d118d05cf4a2145f5ae Env vars only visible by the first process in the container (CMD or ENTRY) $ docker run -it slok/redis /bin/bash root@55e3762daa10:/# redis-cli Could not connect to Redis at 127.0.0.1:6379: Connection refused docker run -it --link redis:db slok/redis /bin/bash root@d5a1e38b5d4e:/# redis-cli -h $DB_PORT_6379_TCP_ADDR -p $DB_PORT_6379_TCP_PORT 172.17.0.37:6379> set "hello" "world" OK 172.17.0.37:6379> get "hello" "world" 172.17.0.37:6379>
-v /opt ubuntu:14.04 /bin/bash root@46293ef28846:/# echo "print('Hello world')" > /opt/say_hello.py Volume created! $ docker run -it --volumes-from doge_container ubuntu:14.04 /bin/bash root@491ad4c3df84:/# ls -la /opt/ total 12 drwxr-xr-x 2 root root 4096 Jul 3 18:00 . drwxr-xr-x 53 root root 4096 Jul 3 18:02 .. -rw-r--r-- 1 root root 21 Jul 3 18:00 say_hello.py root@491ad4c3df84:/# python3 /opt/say_hello.py Hello world this container will mount all volumes from “doge_container” container This is used to share directories across containers There is a pattern called data volume container (Check patterns section)
/usr /root /bin /opt /usr /root /var/lib/docker/vfs/dir/ b7eb1d8264db8716c0a536e0c776d935bc3eada671a26194d1129066aa2a41c4 45832b9c9b3117ee86778df6b6dafdeead36fb643494822cf40f095da0766baa /usr /opt /home Simple principle, mount directories from host OS to containers ... ... ... This was the volume creator, to mount his volumes we need to use it as reference with “volumes-from” ...
for comments First instruction is FROM No case sensitive (std says instructions in uppercase) Some instructions create a new layer Lets check the com m ands
slok/redis ... The base image, tells docker where to start from building the image Needs to be the first instruction in the Dockerfile Dockerfile FROM crosbymichael/python ... If no tag is specified then “latest“ will be taken
Dockerfile RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list ... Dockerfile RUN ["wget", "http://python-distribute.org/distribute_setup.py"] ... Creates a new layer This layers are used as cache for other builds if they are the same Executes actions/commands
Dockerfile RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list ... Dockerfile RUN ["wget", "http://python-distribute.org/distribute_setup.py"] ... Creates a new layer This layers are used as cache for other builds if they are the same Executes actions/commands Uses /sh/bin -c {RUN_ARGUMENTS} Uses exec format
env vars, this will be available for the next RUN instructions the containers that run from the built image will have the env vars setted Dockerfile ENV APP_ENVIRONMENT sandbox ... Dockerfile ENV DOGE such_env_var ...
8125/udp ... Dockerfile EXPOSE 80:8080 ... Map private exposed ports to public ones when running the container Never map public ports inside the Dockerfile
8125/udp ... Dockerfile EXPOSE 80:8080 ... Map private exposed ports to public ones when running the container Never map public ports inside the Dockerfile Private TCP port Private UDP port 80 Private TCP port mapped to 8080 public TCP port
["/data", "/etc/nginx/sites-enabled", "/var/log/nginx"] ... Dockerfile EXPOSE /opt/data:/data ... Mount public paths to private paths when running the container Never mount public to paths inside the Dockerfile
["/data", "/etc/nginx/sites-enabled", "/var/log/nginx"] ... Dockerfile EXPOSE /opt/data:/data ... Mount public paths to private paths when running the container Never mount public to paths inside the Dockerfile mount container /data in host /mnt/opt Create multiple volumes Create /data volume
next RUN instructions don’t cache Dockerfile ADD ./statsd_config.js /var/lib/statsd/config.js ... If src is a tar archive, this will be copied and extracted ADD is to magical, use COPY instead when not extracting is needed (v1.0>=) Copy a relative (to dockerfile) file or directory into the image Dockerfile ADD postgresql.conf etc/postgresql/$PG_VERSION/main/postgresql.conf ... Dockerfile ADD /tar/apache-tomcat-7.0.47.tar.gz /opt ...
next RUN instructions don’t cache Dockerfile ADD ./statsd_config.js /var/lib/statsd/config.js ... If src is a tar archive, this will be copied and extracted ADD is to magical, use COPY instead when not extracting is needed (v1.0>=) Copy a relative (to dockerfile) file or directory into the image Dockerfile ADD postgresql.conf etc/postgresql/$PG_VERSION/main/postgresql.conf ... Dockerfile ADD /tar/apache-tomcat-7.0.47.tar.gz /opt ... This will extract the archive in images /opt
or directory into the image After the first COPY instructions the next RUN instructions don’t cache Similar to ADD Dockerfile ADD ./statsd_config.js /var/lib/statsd/config.js ... Dockerfile COPY postgresql.conf etc/postgresql/$PG_VERSION/main/postgresql.conf ... Dockerfile COPY /tar/apache-tomcat-7.0.47.tar.gz /opt ...
or directory into the image After the first COPY instructions the next RUN instructions don’t cache Similar to ADD Dockerfile ADD ./statsd_config.js /var/lib/statsd/config.js ... Dockerfile COPY postgresql.conf etc/postgresql/$PG_VERSION/main/postgresql.conf ... Dockerfile COPY /tar/apache-tomcat-7.0.47.tar.gz /opt ... This will not extract the archive in images /opt
RUN, CMD and ENTRYPOINT that follow it Dockerfile WORKDIR /etc/nginx ... Dockerfile WORKDIR /opt ... WORKDIR virtualenvs ... Could be use with absolute or relative paths
RUN, CMD and ENTRYPOINT that follow it Dockerfile WORKDIR /etc/nginx ... Dockerfile WORKDIR /opt ... WORKDIR virtualenvs ... Could be use with absolute or relative paths This will end in /opt/virtualenvs
RUN /usr/local/bin/python-build --dir /src/app ... ONBUILD doesn’t affect this image built Triggered when another image is built based on this one Grand-child images doesn’t inherit this ONBUILD (Only direct ones) Dockerfile ONBUILD ADD . /opt/rails_demo ONBUILD WORKDIR /opt/rails_demo ONBUILD RUN rvm all do bundle install ONBUILD CMD rvm all do bundle exec rails server ...
exec docker run executable params... Only one CMD entry per dockerfile Used with ENTRYPOINT is very powerful Dockerfile CMD ["/usr/local/bin/diamond", "-f"] ... Dockerfile CMD echo "This is a test." | wc - ... Dockerfile CMD ["--help"] ... Used to execute a command when running the container
exec docker run executable params... Only one CMD entry per dockerfile Used with ENTRYPOINT is very powerful Dockerfile CMD ["/usr/local/bin/diamond", "-f"] ... Dockerfile CMD echo "This is a test." | wc - ... Dockerfile CMD ["--help"] ... Used to execute a command when running the container Array form: used like exec (Preferred form) As shell (/bin/sh -c) Used to pass params to ENTRYPOINT
Only one ENTRYPOINT entry per dockerfile Used with CMD is very powerful Pass params to ENTRYPOINT with docker run {image} -d ... Dockerfile ENTRYPOINT ["/usr/bin/influxdb", "-config=/opt/influxdb/shared/config.toml"] ... Dockerfile ENTRYPOINT supervisor ... Used to execute a command when running the container Array form: used like exec (Preferred form) As shell (/bin/sh -c)
Only one ENTRYPOINT entry per dockerfile Used with CMD is very powerful Pass params to ENTRYPOINT with docker run {image} -d ... Dockerfile ENTRYPOINT ["/usr/bin/influxdb", "-config=/opt/influxdb/shared/config.toml"] ... Dockerfile ENTRYPOINT supervisor ... Used to execute a command when running the container
pid /run/nginx.pid; events { worker_connections 768; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } This is needed to run the process as a docker container
Install nginx RUN sudo apt-get update RUN sudo apt-get install -y nginx VOLUME ["/etc/nginx", "/var/log/nginx"] EXPOSE 80 443 COPY nginx.conf /etc/nginx/nginx.conf # This image should only run nginx, don't allow command overwrite ENTRYPOINT ["nginx"] We could change the settings and add new websites without rebuilding the image
slok/nginx e55dd17a1b586f407d41eb93eaaf561c9f32609a7eab6e29c41e5f4dc50f3ebc $ curl 192.168.100.55:10080 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
--name postgresql-data postgresql-data fa64af7626476c7d39ca540d221f0c826630a44fd35c4d1222e99809b978205d $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES fa64af762647 postgresql-data:latest /bin/sh 50 seconds ago Exited (0) postgresql-data Remember! volumes persist with stopped containers too, that’s the key $ docker run -d --name postgresql-data -v /var/lib/postgresql busybox 99a239a8aca33baac21c897f7ce1342866517f1f30fdac4c28108c28de1b707b Same result but without using Dockerfiles, although using Dockerfiles is encourage
Xabier Larrakoetxea <slok69@gmail.com> RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list RUN apt-get update RUN apt-get -y -q install python-software-properties software-properties-common RUN apt-get -y -q install postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3 USER postgres RUN /etc/init.d/postgresql start &&\ psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\ createdb -O docker docker # Cofigure the database to use our data dir. RUN sed -i -e"s/data_directory =.*$/data_directory = '\/data'/" /etc/postgresql/9.3/main/postgresql.conf RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf EXPOSE 5432 VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"] CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
postgresql /usr/lib/postgresql/9.3/bin/initdb -D /data fa64af7626476c7d39ca540d221f0c826630a44fd35c4d1222e99809b978205d $ docker run -d --name postgresql-data postgresql-data f2392b5be7cc83368c458d00e1ce7d23306b91b274aba22edc0b20e088b2024b 1st run the data container(We made previously) only the first time 2nd run the app container but initializing the database (will exit) only the first time $ docker run -d --volumes-from postgresql-data postgresql fa67e31dc8782c8e82933540a1aaa0c1a6a03d2c565b57d700a58f623d3c6504 Run the app container(Init postgres database)
(Vagrant) and CI purpouse (Jenkins) Don’t use for production FS /usr ... /lib ... Supervisor /root /opt /var postgres nginx redis uwsgi workers workers Use supervisor or monit to manage all the containers
production and CI purpouse (Jenkins) FS /usr ... /lib ... Supervisor nginx uwsgi Use supervisor or monit to manage all the containers db container FS /usr ... /lib Supervisor redis postgres volume Easy management