├── DockerServices.md ├── DockerSwarmLabVotingApp.md ├── DockerSwarmTutorial.md ├── DockerVolumeExercise.md ├── DockerVotingApp ├── Dockerfile.txt ├── Explore.url ├── docker-compose.yml ├── docker-stack.yml ├── zekeLabs_Docker_VotingApp.pptx └── ~$zekeLabs_Docker_VotingApp.pptx ├── Dockerfile2 ├── HostingWebsiteInContainer.md ├── README.md ├── docker-compose-file.yml ├── docker-usual-commands.md ├── dockerMonitoring.md ├── dockerRegistry.md ├── dockerVolumeExcercise2.md ├── docker_container_commands.md ├── docker_images_commands.md ├── docker_services_commands.md ├── dockerfile ├── java-resources.md ├── multi-stage-build.md ├── network-exercise.md ├── sampleDockerfile ├── sampleDockerfileDotnet └── setting-up-docker.md /DockerServices.md: -------------------------------------------------------------------------------- 1 | Create a service with nginx image 2 | 3 | $ docker service create nginx 4 | 5 | Create nginx service with a name 6 | 7 | $ docker service create --name my_web nginx 8 | 9 | List services: 10 | 11 | $ docker service ls 12 | 13 | Login to a private registry 14 | 15 | $ docker login registry.example.com 16 | $ docker service create --with-registry-auth --name my_service registry.example.com/acme/my_image:latest 17 | 18 | Update a service 19 | 20 | $ docker service update --publish-add 80 my_zekelabs ## Adding a port 80 with the service for outside world 21 | 22 | Create a service with various options 23 | 24 | $ docker service create --name zekeCalling --env MYVAR=myvalue --workdir /tmp --user my_user alpine ping docker.com 25 | 26 | Create a service with 3 containers with port forwarding 27 | 28 | $ docker service create --name my_web --replicas 3 --publish published=8080, target=80 nginx 29 | -------------------------------------------------------------------------------- /DockerSwarmLabVotingApp.md: -------------------------------------------------------------------------------- 1 | Access the voting-app code at 2 | https://github.com/dockersamples/example-voting-app 3 | 4 | ## on Master Node : 5 | 6 | $yum install docker 7 | $service docker start 8 | $docker swarm init --advertise-addr $(hostname -i) 9 | 10 | Download the code 11 | 12 | $yum install git -y 13 | $git clone https://github.com/docker/example-voting-app 14 | 15 | $cd example-voting-app 16 | $cat docker-stack.yml 17 | 18 | Deploy the stack 19 | 20 | $docker stack deploy --compose-file=docker-stack.yml voting_stack 21 | $docker stack ls 22 | 23 | For each services do --- 24 | 25 | $docker stack services voting_stack 26 | $docker service ps voting_stack_vote 27 | 28 | scale a service: 29 | 30 | $docker service scale voting_stack_vote=5 31 | 32 | $docker service ls 33 | 34 | $docker service update --replicas 2 voting_stack_vote 35 | 36 | $docker service update --replicas 2 voting_stack_redis 37 | 38 | ## On Worker Node: 39 | 40 | $yum install docker 41 | 42 | $service docker start 43 | 44 | $docker swarm join --token SWMTKN-1-3gs4q4rqygek2dalg3adauucjgqem3d6058yzwwt7rq6kugl01-1s0r6qevn4idfy87nmy11lhvj 192.168.0.28:2377 45 | 46 | 47 | 48 | ########################## 49 | To create swarm using Hyper V container 50 | https://www.cardinalsolutions.com/blog/2017/06/docker_swarm_mode_part_1 51 | 52 | -------------------------------------------------------------------------------- /DockerSwarmTutorial.md: -------------------------------------------------------------------------------- 1 | ## At Leader: 2 | 3 | docker swarm init 4 | 5 | docker node ls 6 | docker service create -p 80:80 --name web nginx:latest 7 | docker service ls 8 | 9 | curl http://localhost:80 10 | docker node ls 11 | docker ps 12 | docker service inspect web 13 | docker service scale web=15 14 | docker service ps web 15 | docker node update --availability drain node2 16 | docker service ps web 17 | docker ps 18 | docker ps|wc -l 19 | docker service scale web=15 20 | docker ps|wc -l 21 | docker service scale web=10 22 | docker ps|wc -l 23 | docker service ps web 24 | docker node update --availability active node2 25 | docker service ps web 26 | docker node ls 27 | docker node inspect node2 --pretty 28 | 29 | ## AT worker node2 30 | 31 | docker swarm join --token SWMTKN-1-3jqt6ertjmu2to60vu0ddraelkpne9shzth3igefxk85iow7b0-4cscwbsrtskgpalsumcivpl8u 192.168.0.18:2377 32 | docker ps -a 33 | docker node ls 34 | curl http://localhost:80 35 | docker ps 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /DockerVolumeExercise.md: -------------------------------------------------------------------------------- 1 | ## Using Docker Volume 2 | 3 | - Create a directory in your 'user' home directory called 'docker'. 4 | - Within that directory, create another directory called 'mydata'. 5 | - Within mydata, create a file called 'zekeData.txt' containing any text message you want. 6 | 7 | [user@zekelabs ~]$ mkdir docker 8 | [user@zekelabs ~]$ cd docker 9 | [user@zekelabs ~]$ mkdir mydata 10 | [user@zekelabs ~]$ cd mydata 11 | [user@zekelabs mydata]$ ll 12 | total 0 13 | [user@zekelabs mydata]$ echo "This is data originally kept in a file at Docker host" >> zekeData.txt 14 | [user@zekelabs mydata]$ ll 15 | total 4 16 | -rw-rw-r-- 1 user user 18 Dec 15 15:21 zekeData.txt 17 | [user@zekelabs mydata]$ cd .. 18 | [user@zekelabs docker]$ ll 19 | total 0 20 | drwxrwxr-x 2 user user 23 Dec 15 15:21 mydata 21 | 22 | 23 | 2. Create a docker container name 'local_vol' from the 'centos:6' image. 24 | - The container should be created in interactive mode, 25 | - attached to the current terminal and running the bash shell. 26 | 27 | - Finally create the container with a volume (or directory) called 'containerDirectory' 28 | - so that the system will automatically create the directory/mount when the container starts. 29 | 30 | [user@zekelabs docker]$ docker run -it --name="local_vol" -v /containerDirectory centos:6 /bin/bash 31 | 32 | [root@191131068f8c /]# 33 | 34 | 35 | 3. List the filesystems within the container, specifically looking for the volume/directory that was added to the container during creation. 36 | 37 | [root@191131068f8c /]# df -h 38 | Filesystem Size Used Avail Use% Mounted on 39 | rootfs 9.8G 254M 9.0G 3% / 40 | /dev/mapper/docker-8:2-203558447-191131068f8ceffe6fb38198a61b9806f27e4d22de3c8b0d2aec4c0c4fe7f88d 41 | 9.8G 254M 9.0G 3% / 42 | tmpfs 2.0G 0 2.0G 0% /dev 43 | shm 64M 0 64M 0% /dev/shm 44 | /dev/sda2 36G 4.3G 32G 12% /containerDirectory 45 | tmpfs 2.0G 0 2.0G 0% /run/secrets 46 | /dev/sda2 36G 4.3G 32G 12% /etc/resolv.conf 47 | /dev/sda2 36G 4.3G 32G 12% /etc/hostname 48 | /dev/sda2 36G 4.3G 32G 12% /etc/hosts 49 | tmpfs 2.0G 0 2.0G 0% /proc/kcore 50 | tmpfs 2.0G 0 2.0G 0% /proc/timer_stats 51 | [root@191131068f8c /]# ls -al /containerDirectory/ 52 | total 4 53 | drwxr-xr-x 2 root root 6 Dec 15 20:46 . 54 | drwxr-xr-x 23 root root 4096 Dec 15 20:46 .. 55 | [root@191131068f8c /]# 56 | 57 | 58 | 59 | 4. Exit the container. This time, lets create another container called 'remote_vol' 60 | - with the same container configuration except when creating the volume in the container, 61 | - link the volume name 'mydata' to the underlying host directory structure created in Step #1. 62 | 63 | [user@zekelabs docker]$ docker run -it --name="remote_vol" -v /home/user/docker/mydata:/mydata centos:6 /bin/bash 64 | [root@fnasfavdvadjv /]# 65 | 66 | 67 | 5. Once the container is started, list the disk mounts and verify the remote (host) volume is mounted. 68 | 69 | [root@fnasfavdvadjv /]# df -h 70 | 71 | Filesystem Size Used Avail Use% Mounted on 72 | 73 | rootfs 9.8G 254M 9.0G 3% / 74 | 75 | /dev/mapper/docker-8:2-203558447-fnasfavdvadjva74f4e0e65efd02191685570ef89995d57716a2ff09c3078d7f8 76 | 77 | 9.8G 254M 9.0G 3% / 78 | 79 | tmpfs 2.0G 0 2.0G 0% /dev 80 | 81 | shm 64M 0 64M 0% /dev/shm 82 | 83 | ... 84 | 85 | tmpfs 2.0G 0 2.0G 0% /proc/timer_stats 86 | 87 | 6. Change to that directory and verify that the text file created in Step #1 appears with the content created. 88 | 89 | [root@fnasfavdvadjv /]# ls -al /mydata/ 90 | 91 | total 8 92 | 93 | drwxrwxr-x 2 1000 1000 23 Dec 15 20:21 . 94 | 95 | drwxr-xr-x 23 root root 4096 Dec 15 20:51 .. 96 | 97 | -rw-rw-r-- 1 1000 1000 18 Dec 15 20:21 zekeData.txt 98 | 99 | [root@fnasfavdvadjv /]# cat /mydata/zekeData.txt 100 | 101 | This is data originally kept in a file at Docker host 102 | 103 | [root@fnasfavdvadjv /]# 104 | -------------------------------------------------------------------------------- /DockerVotingApp/Dockerfile.txt: -------------------------------------------------------------------------------- 1 | FROM microsoft/dotnet:2.0.0-sdk 2 | 3 | WORKDIR /code 4 | 5 | ADD src/Worker /code/src/Worker 6 | 7 | RUN dotnet restore -v minimal src/Worker \ 8 | && dotnet publish -c Release -o "./" "src/Worker/" 9 | 10 | CMD dotnet src/Worker/Worker.dll -------------------------------------------------------------------------------- /DockerVotingApp/Explore.url: -------------------------------------------------------------------------------- 1 | [InternetShortcut] 2 | URL=https://github.com/explore 3 | -------------------------------------------------------------------------------- /DockerVotingApp/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | vote: 5 | build: ./vote 6 | command: python app.py 7 | volumes: 8 | - ./vote:/app 9 | ports: 10 | - "5000:80" 11 | networks: 12 | - front-tier 13 | - back-tier 14 | 15 | result: 16 | build: ./result 17 | command: nodemon server.js 18 | volumes: 19 | - ./result:/app 20 | ports: 21 | - "5001:80" 22 | - "5858:5858" 23 | networks: 24 | - front-tier 25 | - back-tier 26 | 27 | worker: 28 | build: 29 | context: ./worker 30 | depends_on: 31 | - "redis" 32 | networks: 33 | - back-tier 34 | 35 | redis: 36 | image: redis:alpine 37 | container_name: redis 38 | ports: ["6379"] 39 | networks: 40 | - back-tier 41 | 42 | db: 43 | image: postgres:9.4 44 | container_name: db 45 | volumes: 46 | - "db-data:/var/lib/postgresql/data" 47 | networks: 48 | - back-tier 49 | 50 | volumes: 51 | db-data: 52 | 53 | networks: 54 | front-tier: 55 | back-tier: -------------------------------------------------------------------------------- /DockerVotingApp/docker-stack.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | 4 | redis: 5 | image: redis:alpine 6 | ports: 7 | - "6379" 8 | networks: 9 | - frontend 10 | deploy: 11 | replicas: 1 12 | update_config: 13 | parallelism: 2 14 | delay: 10s 15 | restart_policy: 16 | condition: on-failure 17 | db: 18 | image: postgres:9.4 19 | volumes: 20 | - db-data:/var/lib/postgresql/data 21 | networks: 22 | - backend 23 | deploy: 24 | placement: 25 | constraints: [node.role == manager] 26 | vote: 27 | image: dockersamples/examplevotingapp_vote:before 28 | ports: 29 | - 5000:80 30 | networks: 31 | - frontend 32 | depends_on: 33 | - redis 34 | deploy: 35 | replicas: 2 36 | update_config: 37 | parallelism: 2 38 | restart_policy: 39 | condition: on-failure 40 | result: 41 | image: dockersamples/examplevotingapp_result:before 42 | ports: 43 | - 5001:80 44 | networks: 45 | - backend 46 | depends_on: 47 | - db 48 | deploy: 49 | replicas: 1 50 | update_config: 51 | parallelism: 2 52 | delay: 10s 53 | restart_policy: 54 | condition: on-failure 55 | 56 | worker: 57 | image: dockersamples/examplevotingapp_worker 58 | networks: 59 | - frontend 60 | - backend 61 | deploy: 62 | mode: replicated 63 | replicas: 1 64 | labels: [APP=VOTING] 65 | restart_policy: 66 | condition: on-failure 67 | delay: 10s 68 | max_attempts: 3 69 | window: 120s 70 | placement: 71 | constraints: [node.role == manager] 72 | 73 | visualizer: 74 | image: dockersamples/visualizer:stable 75 | ports: 76 | - "8080:8080" 77 | stop_grace_period: 1m30s 78 | volumes: 79 | - "/var/run/docker.sock:/var/run/docker.sock" 80 | deploy: 81 | placement: 82 | constraints: [node.role == manager] 83 | 84 | networks: 85 | frontend: 86 | backend: 87 | 88 | volumes: 89 | db-data: -------------------------------------------------------------------------------- /DockerVotingApp/zekeLabs_Docker_VotingApp.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishrpandey/DockerTraining/a9468125e373236a4143c61fcadd49d7ea050d4b/DockerVotingApp/zekeLabs_Docker_VotingApp.pptx -------------------------------------------------------------------------------- /DockerVotingApp/~$zekeLabs_Docker_VotingApp.pptx: -------------------------------------------------------------------------------- 1 | zekeLabs zekeLabs -------------------------------------------------------------------------------- /Dockerfile2: -------------------------------------------------------------------------------- 1 | FROM centos:6 2 | 3 | LABEL maintainer="ashish.pandey@zekelabs.com" 4 | 5 | RUN yum install -y httpd net-tools && \ 6 | mkdir -p /run/httpd && \ 7 | rm -rf /run/http/* /tmp/httpd* 8 | 9 | CMD echo "This is a Dockerfile test message" 10 | 11 | ENV ENVIRONMENT=”production” 12 | 13 | EXPOSE 80 14 | 15 | CMD ["-D","FOREGROUND"] 16 | 17 | ENTRYPOINT ["apachectl"] 18 | -------------------------------------------------------------------------------- /HostingWebsiteInContainer.md: -------------------------------------------------------------------------------- 1 | # Run an ubuntu container 2 | 3 | docker pull ubuntu 4 | docker run -it -d -p 80:80 ubuntu:latest 5 | docker attach 6 | 7 | ## in the container --> 8 | apt update 9 | apt-get install apache2 -y 10 | apt-get install vim -y 11 | service apache2 start 12 | apt-get install elinks -y 13 | 14 | elinks http://localhost:80/index.html ## this will show the website on command line interface itself 15 | 16 | ## copy your web content in /var/www/html directory 17 | 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DockerTraining 2 | This repository has the contents used in Docker training. 3 | -------------------------------------------------------------------------------- /docker-compose-file.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | web: 4 | image: nginx:latest 5 | deploy: 6 | replicas: 5 7 | resources: 8 | limits: 9 | cpus: "0.1" 10 | memory: 50M 11 | restart_policy: 12 | condition: on-failure 13 | ports: 14 | - "8000:80" 15 | networks: 16 | - alpine-net 17 | networks: 18 | alpine-net: 19 | -------------------------------------------------------------------------------- /docker-usual-commands.md: -------------------------------------------------------------------------------- 1 | ## Basic commands 2 | 3 | $ docker images ##lists all images available locally 4 | 5 | $ docker search ## search the repository docker-hub for all the images containg 6 | $ docker search centos 7 | 8 | $ docker pull hello-world ## Download hello-world image to local host machine from docker-hub repo 9 | $ docker images 10 | $ docker run hello-world:latest ## Run latest version of hello-world 11 | OR 12 | $ docker run 13 | 14 | other examples 15 | $ docker pull centos:centos6 ##centos6 is the version tag 16 | ''' 17 | Hello-world is an ephemeral container. Ran and exited. 18 | In images it can have multiple layers/snapshot over that image e.g. 19 | base layer: package layer: configuration layer 20 | ''' 21 | 22 | ## To look about details of image 23 | $ docker inspect 24 | 25 | $ docker pull docker/whalesay ## Download docker/whalesay image to local host machine from docker-hub repo 26 | $ docker run docker/whalesay cowsay IAMWHALE ## run container 27 | __________ 28 | < IAMWHALE > 29 | ---------- 30 | \ 31 | \ 32 | \ 33 | ## . 34 | ## ## ## == 35 | ## ## ## ## === 36 | /""""""""""""""""___/ === 37 | ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ 38 | \______ o __/ 39 | \ \ __/ 40 | \____\______/ 41 | 42 | 43 | 44 | $ docker ps ## lists the containers running 45 | $ docker ps -a ## gives all the containers that ran in the past 46 | $ docker inspect ## Gives jason object enumerating details of the running container 47 | 48 | $ docker run -it centos:latest /bin/bash ## -I iteractive mode , -t on terminal; create a bash shell 49 | ## It will instantly login to the container and launch a bash 50 | ##shell. On exiting bash shell the container will also terminate. 51 | 52 | ## to avoid that run with -d command: 53 | 54 | $ docker run -d centos:latest /bin/bash ## it shall return a container id only 55 | ## and container will be exited 56 | 57 | $ docker stop container id ### will kill the container 58 | $ docker ps ## check it with "docker ps" command 59 | $ docker ps -a ## will show killed containers 60 | 61 | $ docker run -d --name=mycontainername imagename:imageversion ## Give container a name 62 | $ docker inspect mycontainername 63 | 64 | $ docker attach container_name/id ## control will attach to the container and exitig from their will bring down the container itself 65 | 66 | $ docker exec -it containername /bin/bash ## it will launch a bash shell and jump to this bash shell running in the container. exiting from here will just exit from bash shell 67 | 68 | $ docker restart container_name ## restart the container 69 | 70 | ### Image and container management: 71 | 72 | $ docker rmi centos:centos6 ## remove images only if no containers are running on it. 73 | 74 | $ docker rm container_id ### removes the container 75 | $ docker rm `docker ps -a -q ` ### removes all the containers 76 | 77 | ## if we do now 78 | $ docker rmi ## it will remove the image 79 | ## use -f option to forcefully remove the image even if containers are runnning 80 | 81 | 82 | -------------------------------------------------------------------------------- /dockerMonitoring.md: -------------------------------------------------------------------------------- 1 | ## Docker monitoring: 2 | 3 | ### docker info 4 | 5 | system wide info regarding the Docker installation. Information displayed includes the kernel version, number of containers and images. 6 | 7 | $ docker info 8 | 9 | ### docker stats 10 | 11 | Memory and CPU utilization of containers. similar to the "top" command on linux 12 | 13 | $docker stats 14 | 15 | ### docker logs 16 | 17 | To see the logs of the container 18 | 19 | $ docker logs container_name 20 | 21 | ### Monitor the image 22 | 23 | Look at the history of the image 24 | 25 | $ docker history --no-trunc 26 | 27 | ### docker events 28 | 29 | Use it to get real-time events from the server. 30 | 31 | $ docker events 32 | 33 | You can customize it with options 34 | 35 | $ docker events --filter event=attach --filter event=stop --filter event=die 36 | 37 | # Backup 38 | 39 | ## Docker backup of image 40 | 41 | $ docker save --output centos.latest.tar centos:latest 42 | $ docker save centos:latest > centos-latest.tar 43 | 44 | check the content of .tar file by running 45 | 46 | $ tar tvf centos-latest.tar 47 | 48 | ## restore the image from tar file 49 | 50 | $ docker load 25 | 26 | Remove the specified container from this machine 27 | 28 | $docker rm 29 | 30 | Remove all containers from this machine 31 | 32 | $docker rm $(docker ps -a -q) 33 | 34 | Run image from a registry 35 | 36 | $docker run username/repository:tag 37 | 38 | -------------------------------------------------------------------------------- /docker_images_commands.md: -------------------------------------------------------------------------------- 1 | 2 | Show images on this machine 3 | 4 | $docker images 5 | 6 | Pull images to local docker host from docker store 7 | 8 | $docker pull image_name:tag_name 9 | 10 | Show all images on this machine 11 | 12 | $docker images -a 13 | 14 | Remove the specified image from this machine 15 | 16 | $docker rmi 17 | 18 | Remove all images from this machine 19 | 20 | $docker rmi $(docker images -q) 21 | 22 | ## Image Lifecycle development 23 | 24 | Create image using this directory's Dockerfile 25 | 26 | $docker build -t dir_containing_dockerfile . 27 | 28 | Create image from a container 29 | 30 | $docker commit container_name image_repo:tag 31 | 32 | Log in this CLI session using your Docker credentials 33 | 34 | $docker login 35 | 36 | Tag for upload to registry 37 | OR rename the image 38 | 39 | $docker tag username/repository:tag 40 | 41 | Upload tagged image to registry 42 | 43 | $docker push username/repository:tag 44 | 45 | Run image from a registry 46 | 47 | $docker run username/repository:tag 48 | 49 | -------------------------------------------------------------------------------- /docker_services_commands.md: -------------------------------------------------------------------------------- 1 | Using Docker Stack tool to deploy services 2 | 3 | docker stack ls # List all running applications on this Docker host 4 | docker stack deploy -c # Run the specified Compose file 5 | docker stack services # List the services associated with an app 6 | docker stack ps # List the running containers associated with an app 7 | docker stack rm # Tear down an application 8 | -------------------------------------------------------------------------------- /dockerfile: -------------------------------------------------------------------------------- 1 | # Use an official Python runtime as a base image 2 | FROM python:2.7-slim 3 | 4 | # Set the working directory to /app 5 | WORKDIR /app 6 | 7 | # Copy the current directory contents into the container at /app 8 | ADD . /app 9 | 10 | # Install any needed packages specified in requirements.txt 11 | RUN pip install -r requirements.txt 12 | 13 | # Make port 80 available to the world outside this container 14 | EXPOSE 80 15 | 16 | # Define environment variable 17 | ENV NAME World 18 | 19 | # Run app.py when the container launches 20 | CMD ["python", "app.py"] 21 | -------------------------------------------------------------------------------- /java-resources.md: -------------------------------------------------------------------------------- 1 | 2 | Good resources for Java containers: 3 | 4 | https://www.javatpoint.com/docker-java-example 5 | 6 | https://stackify.com/guide-docker-java/ 7 | 8 | https://runnable.com/docker/java/dockerize-your-java-application 9 | 10 | https://github.com/docker/labs/tree/master/developer-tools/java/ 11 | 12 | https://github.com/docker/labs/blob/master/developer-tools/java/chapters/ch03-build-image.adoc 13 | -------------------------------------------------------------------------------- /multi-stage-build.md: -------------------------------------------------------------------------------- 1 | Docker Documentation at: 2 | https://docs.docker.com/develop/develop-images/multistage-build/ 3 | 4 | Blog used in the documentation: 5 | https://blog.alexellis.io/mutli-stage-docker-builds/ 6 | 7 | code used in the above blog: 8 | https://github.com/alexellis/href-counter 9 | 10 | -------------------------------------------------------------------------------- /network-exercise.md: -------------------------------------------------------------------------------- 1 | ## Without custom network 2 | Using only default bridge 3 | 4 | Show current networks 5 | 6 | $ docker network ls 7 | 8 | Run 2 containers with default bridge network 9 | 10 | $ docker run -dit --name alpine1 alpine ash 11 | 12 | $ docker run -dit --name alpine2 alpine ash 13 | 14 | $ docker container ls 15 | 16 | Get more info about the default network 17 | 18 | $ docker network inspect bridge 19 | 20 | Attach to a running container 21 | 22 | $ docker attach alpine1 23 | 24 | $ip addr show 25 | 26 | $ping -c 2 google.com 27 | Success 28 | 29 | 30 | $ping -c 2 31 | Success 32 | 33 | 34 | $ping -c 2 alpine2 35 | Fails 36 | 37 | // Remove all the containers 38 | 39 | $ docker container stop alpine1 alpine2 40 | 41 | $ docker container rm alpine1 alpine2 42 | 43 | 44 | # With custom bridge network 45 | 46 | 47 | $ docker network create --driver bridge alpine-net // create a user defined network alpine-net 48 | 49 | $ docker network ls 50 | 51 | $ docker network inspect alpine-net 52 | 53 | ## Run container with custom brisge network alpine-net 54 | 55 | $ docker run -dit --name alpine1 --network alpine-net alpine ash 56 | 57 | $ docker run -dit --name alpine2 --network alpine-net alpine ash 58 | 59 | $ docker run -dit --name alpine3 alpine ash //alpine3 only connected to bridge not to alpine-net 60 | 61 | $ docker run -dit --name alpine4 --network alpine-net alpine ash 62 | 63 | $ docker network connect bridge alpine4 //alpine4 connect to bridge as well 64 | 65 | 66 | $ docker network inspect bridge 67 | 68 | $ docker network inspect alpine-net 69 | 70 | 71 | Ping from one container to others by name and see the connectivity 72 | ping from alpine4 which is connected to both 73 | 74 | ## Extras 75 | 76 | Compare the output of following commands: 77 | 78 | docker run -it alpine ip addr show 79 | and 80 | 81 | docker run -it --net=host alpine ip addr show 82 | 83 | By changing the namespace to host, the process will have access to the host machines network interface. 84 | 85 | 86 | This is similar to the process namespace 87 | Compare the output of the two commands given below 88 | 89 | docker run -it alpine ps aux 90 | docker run -it --pid=host alpine ps aux 91 | 92 | Check the routing table rules using 93 | 94 | netstat -r 95 | 96 | -------------------------------------------------------------------------------- /sampleDockerfile: -------------------------------------------------------------------------------- 1 | # Use an official Python runtime as a base image 2 | FROM python:2.7-slim 3 | 4 | # Set the working directory to /app 5 | WORKDIR /app 6 | 7 | # Copy the current directory contents into the container at /app 8 | ADD . /app 9 | 10 | # Install any needed packages specified in requirements.txt 11 | RUN pip install -r requirements.txt 12 | 13 | # Make port 80 available to the world outside this container 14 | EXPOSE 80 15 | 16 | # Define environment variable 17 | ENV NAME World 18 | 19 | # Run app.py when the container launches 20 | CMD ["python", "app.py"] -------------------------------------------------------------------------------- /sampleDockerfileDotnet: -------------------------------------------------------------------------------- 1 | FROM microsoft/dotnet:2.0.0-sdk 2 | 3 | WORKDIR /code 4 | 5 | ADD src/Worker /code/src/Worker 6 | 7 | RUN dotnet restore -v minimal src/Worker \ 8 | && dotnet publish -c Release -o "./" "src/Worker/" 9 | 10 | CMD dotnet src/Worker/Worker.dll -------------------------------------------------------------------------------- /setting-up-docker.md: -------------------------------------------------------------------------------- 1 | ## For a normal centos/RHEL machine 2 | 3 | 4 | $ sudo yum install -y yum-utils 5 | $ sudo yum-config-manager \ 6 | --add-repo \ 7 | https://download.docker.com/linux/centos/docker-ce.repo 8 | $ sudo yum install docker 9 | $ sudo systemctl start docker 10 | 11 | 12 | ## For Amazon linux 2 - ec2 instances 13 | connect to ec2 instance through putty 14 | 15 | $ sudo su 16 | $ yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 17 | $ yum install docker 18 | $ service docker start 19 | 20 | ## To check whether it has worked correctly 21 | $ docker run hello-world 22 | 23 | """ 24 | Unable to find image 'hello-world:latest' locally 25 | latest: Pulling from library/hello-world 26 | 78445dd45222: Pull complete 27 | Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7 28 | Status: Downloaded newer image for hello-world:latest 29 | 30 | Hello from Docker! 31 | This message shows that your installation appears to be working correctly. 32 | 33 | To generate this message, Docker took the following steps: 34 | 1. The Docker client contacted the Docker daemon. 35 | 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 36 | 3. The Docker daemon created a new container from that image which runs the 37 | executable that produces the output you are currently reading. 38 | 4. The Docker daemon streamed that output to the Docker client, which sent it 39 | to your terminal. 40 | 41 | To try something more ambitious, you can run an Ubuntu container with: 42 | $ docker run -it ubuntu bash 43 | 44 | Share images, automate workflows, and more with a free Docker ID: 45 | https://cloud.docker.com/ 46 | 47 | For more examples and ideas, visit: 48 | https://docs.docker.com/engine/userguide/ 49 | 50 | """ 51 | 52 | For further help for other OS ... Visit official site: 53 | https://docs.docker.com/engine/installation 54 | --------------------------------------------------------------------------------