Docker vs. Git
Image vs. Container
From devops perspective
From developer perspective
How to link multiple containers
Data-only containers
ssh root@dhod -p 20022 # albo: ssh root@10.93.1.226 -p 20022
#password: docker
uname -a
docker run -ti ubuntu uname -a
docker run -ti ubuntu:14.04 uname -a
docker run -ti ubuntu:12.04 uname -a
docker run -ti fedora uname -a
docker run -ti coreos uname -a
type in your console
docker images --tree
... and I don't recommend it
docker images
docker build
docker pull
docker push
docker rmi
docker tag
docker run
docker ps
docker rm
docker exec
docker logs
docker stats
Ports: 22, 80
p: 3306
v: /var/lib/mysql
p: 11211
docker run -p 8080:80 -p 20022:22 --name blog --mem_limit 512mb kszumny/my_blog
blog:
image: kszumny/my_blog
ports:
- "8080:80"
- "20022:22"
mem_limit: 512000000
# fig up -d
docker-compose up -d
docker run -ti noisy/httpd-hello-stx
docker run -ti -p 80:80 noisy/httpd-hello-stx
docker run -ti -P noisy/httpd-hello-stx
#in dhod:
docker run -ti -p 20101:80 --name hello-stx noisy/httpd-hello-stx
docker run -d -p 20101:80 --name hello-stx noisy/httpd-hello-stx
#check dhod:20101/
type in your console
docker ps [-a]
docker exec <container_id/name> bash
docker logs <container_id/name>
docker stats <container_id/name>
fig ps
fig exec
fig logs
fig stop
fig restart
fig scale
FROM
RUN
CMD
EXPOSE
ENV
ADD or COPY
ENTRYPOINT
VOLUME
USER
WORKDIR
ONBUILD
$ sudo passwd bob
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
#!/bin/sh
newpass=42
expect -c "
spawn sudo passwd
expect "?assword:"
send \"$newpass\r\"
expect "?assword:"
send \"$newpass\r\"
expect eof"
docker build --tag <tag> --no-cache <dir>
docker build -t docker-demo .
container
ssh service
pycharm helpers
data only container
docker run -d --name db training/postgres
docker run -d -P --name web --link db:postgresdb training/webapp python app.py
web:
image: yesnault/docker-phabricator
links:
- db:database
ports:
- "8082:80"
db:
image: yesnault/docker-phabricator-mysql
web:
image: yesnault/docker-phabricator
links:
- db:database
ports:
- "8082:80"
db:
image: yesnault/docker-phabricator-mysql
volumes_from:
- data
data:
image: busybox
volumes:
- /var/lib/mysql
web:
image: yesnault/docker-phabricator
links:
- db:database
ports:
- "8082:80"
db:
image: yesnault/docker-phabricator-mysql
volumes_from:
- data
data:
image: yesnault/docker-phabricator-mysql
volumes:
- /var/lib/mysql
entrypoint: /bin/ls
Persistent volumes
docker inspect
# Dockerfile
FROM busybox
VOLUME /var/lib/mysql
CMD /bin/sh
docker build -t mysql_datastore .
docker run -i -t -name mysql_data mysql_datastore
docker run -d --name mysql_data -v /var/lib/mysql busybox
or
fig/docker compose...
or
#fig.yml/docker-compose.yml
web:
build: .
ports:
- "80"
- "443:443"
volumes_from:
- data
volumes:
- /backup:/backup
environment:
- VIRTUAL_HOST=phab.localhost
- VIRTUAL_PORT=80
data:
image: busybox
volumes:
- /var/lib/mysql
- /var/repo
- /opt/phabricator/conf
- /etc/ssl/spistresci
fig up -d # Voilà!
zookeeper:
image: raycoding/piggybank-zookeeper
ports:
- "8383:8383"
- "2181:2181"
- "2888:2888"
- "3888:3888"
environment:
- HOSTNAME=127.0.0.1
database:
image: mysql
environment:
- MYSQL_ROOT_PASSWORD=topsecret
volumes_from:
- data
volumes:
- .:/local/
ports:
- "3306"
command: mysqld
solr:
build: .
volumes_from:
- data
ports:
- "8983:8983"
links:
- zookeeper:ZK
- database:DB
environment:
- SOLR_OPTS="-DzkHost=$ZK_PORT_2181_TCP_ADDR:$ZK_PORT_2181_TCP_PORT"
command: /bin/bash -c '/upconfigs.sh ; /usr/lib/apache-tomcat-7.0.32/bin/catalina.sh run'
data:
image: busybox
volumes:
- /usr/lib/solr-home
- solr.xml:/usr/lib/solr-home/solr.xml
- /var/lib/mysql
sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo service docker restart
Ubuntu:
$ curl -sSL https://get.docker.com/ubuntu/ | sudo sh
Other:
do not use apt-get to install docker
use:
docker ps -a | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm
Remove old containers
docker rm $(docker ps -aq)
# or more explicite
docker rm $(docker ps -a | grep Exited | awk '{print $1}')
Remove all stopped containers
docker-cleanup script:
docker images | grep "<none>" | awk '{print $3}' | xargs docker rmi
Remove all untagged images