Docker Labs for beginners
Set up docker on ubuntu
1. Create below shell script and execute that script
$ cat install-docker.sh
#!/bin/bash
echo "installing docker"
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository \
"deb https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable"
apt-get update && apt-get install -y docker-ce=$(apt-cache madison docker-ce | grep 17.03 | head -1 | awk '{print $3}')
$ chmod a+x install-docker.sh
$ sh install-docker.sh
2. Check if service is up or not
$ systemctl status docker
$ systemctl start docker
3. Check docker version
$ docker --version
1. Create below shell script and execute that script
$ cat install-docker.sh
#!/bin/bash
echo "installing docker"
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository \
"deb https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable"
apt-get update && apt-get install -y docker-ce=$(apt-cache madison docker-ce | grep 17.03 | head -1 | awk '{print $3}')
$ chmod a+x install-docker.sh
$ sh install-docker.sh
2. Check if service is up or not
$ systemctl status docker
$ systemctl start docker
3. Check docker version
$ docker --version
Task
1 :- Hello World
In
your Docker environment, just run the following command:
$
docker run busybox echo hello world
We ran a
single process and echo'ed hello world.
$ docker ps
No container
$ docker ps –a
You will see
the stopped container
Task 2 :- Interactive docker conatiner
$ hostname
$ docker run
-it ubuntu bash
$ hostname
$ exit
$ docker ps
No container
$ docker ps –a
You will see
the stopped container
Task 3:- Run
a container in the background
$ docker run
-d pardeepvirdi/clock
$ docker ps
You can see the container
Task 4 :-
Start container specific name
$ docker
run -d --name myclock pardeepvirdi/clock
Task 5 :- Port mapping
$ docker pull
nginx
$ docker
images
$ docker run
-d -p 80:80 --name webserver-1 nginx
$ docker run -d -p 70:80 --name webserver2 nginx
Lab 2 :- Build
container image
Step 1 :- Create a separate folder for this Lab
$ mkdir example-docker
$ cd example-docker
Step 2 :- create
a new file with name Dockerfile and index.html using any editor
$ vi
Dockerfile
FROM
nginx:1.11-alpine
COPY index.html
/usr/share/nginx/html/index.html
EXPOSE 80
CMD
["nginx", "-g", "daemon off;"]
$ vi
index.html
“my nginx
container”
Step 3 :- Now
we build the image
$ docker build -t
nginx-image:v01 .
Step 4 :- Run a container from image
$ docker run -d -p 80:80 nginx-image:v01
Comments
Post a Comment