Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
List of Docker commands for Demo

Here's the set of command which I will execute while presenting "Docker - A Gentle Introduction".

Pulling images

docker pull alpine
docker image ls 

Building the Image

cd /vagrant/docker/prs-tomcat
vim Dockerfile
docker build . -t my-tomcat
docker build . -t my-tomcat --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy 

docker history my-tomcat

Modify the Dockerfile to also install procps

echo "RUN apt-get install -y procps" >> Dockerfile

Running the Container

docker container run --name my-tomcat-container my-tomcat
ps -ef | grep tomcat
docker ps
docker exec -it my-tomcat-container /bin/bash

Networks - Demo Bridge Network and DNS resolution.

docker network ls
docker network create --driver bridge my-bridge
docker container run -itd --name busy1 busybox
docker container run -itd --name busy2 busybox
docker network connect my-bridge busy1
docker network connect my-bridge busy2
docker network inspect my-bridge
docker attach busy1

Inside busy1, ping busy2 and see DNS resolution

ping busy2

Volumes

docker container run --rm -itd --name busy busybox
docker attach busy
# Inside the container 
    touch persist.txt; \
    echo hello >> persist.txt ;\
    cat persist.txt ;
    exit 

docker container ls --all
docker container run --rm -itd --name busy busybox
docker attach busy
# Inside the container 
    cat persist.txt
    exit

docker container run --rm -itd --name busy -v vol:/volume busybox 
docker attach busy
    touch /volume/persist.txt
    echo hello >> /volume/persist.txt
    cat /volume/persist.txt
    exit

docker container ls --all
docker container run --rm -v vol:/volume busybox cat /volume/persist.txt

docker volume ls  
docker container run --rm  -it --name busy -v $(pwd):/volume1 busybox

Compose

cd ../iip-jenkins
vim docker-compose.yml
docker-compose build
docker-compose up 

Swarm

docker swarm init --advertise-addr <ip-address of the instance>
docker service create alpine ping 8.8.8.8 
docker service update --replicas 3 <serivce-id>
docker container rm -f <container-id>
watch "docker service ls"

5-Node Swarm on PWD

docker node ls 
docker service create --replicas 4 --name four-alpines alpine ping 8.8.8.8  
docker node update --availability drain manager2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.