Vous êtes sur la page 1sur 2

Lab

Title Docker
Duration 60 minutes

1) Launch a Ubuntu 16.04 Instance and perform system update

sudo apt-get update

2) Add Docker Repository to APT source

sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys \


58118E89F3A912897C070ADBF76221572C52609D
sudo apt-get update
sudo apt-add-repository 'deb https://apt.dockerproject.org/repo ubuntu-xenial main'
sudo apt-get update

3) Install Docker and add our user to the docker group

sudo apt-get install -y docker-engine


sudo usermod -aG docker ubuntu

4) Log out and login back as the same user to enable this change. Check that docker is running using
the command and to view system-wide information about Docker

sudo systemctl status docker


docker info

5) Check access to Docker Hub (a docker image registry) by running a simple command

docker run hello-world

6) Search for Ubuntu image in Docker hub and pull it. View the list of images in our machine using
docker images command

docker search ubuntu


docker pull ubuntu
docker images

7) Run the downloaded ubuntu image with interactive shell access by passing options i and t

docker run -it ubuntu

8) Exit the container. Now lets create our own web server image from the ubuntu image. Next clone a
sample php app from git and view the Dockerfile in it by the following commands.

git clone https://github.com/awslabs/ecs-demo-php-simple-app sample_app


cd sample_app
cat Dockerfile

9) Dockerfile contains information about the base image to be used and the operations such as install
packages, configuring the code that are need to be done before creating a new docker image.
10) Now build a docker image with following command. I create my image with name myapache.
-t stands for automatic tagging of our image.

docker build -t myapache .

Run docker images to view your image.


11) Check whether the image is working by running the following command and navigate the browser
to our instances public IP. The following command runs the container as daemon.

docker run -d -p 80:80 myapache

12) To view the containers,

docker ps -a

13) Now we want to modify this image. We can login into the container using the following command

docker exec -it <Container_ID> /bin/bash

14) Change the web page content by running the following command and exit

echo "Hai from modified web page" > /var/www/index.php


exit

15) Now Create a new image from this container using the following command where mymodified is
the name for my new image. Use docker images to check the new image.

docker commit <Container_ID> mymodified

16) To stop and delete the old container, type the following

docker stop <Container_ID>


docker rm <Container_ID>

17) Now start our new image with the same port and check it in the browser

docker run -d -p 80:80 mymodified

18) Additionally, you can push your images to your docker hub account. For that, login using the
following command. You can sign up at https://hub.docker.com

docker login -u <dockerhub_ID>

19) Tag image and push it to the docker hub using the following commands.

docker tag mymodified:latest <dockerhub_ID>/mymodified:latest


docker push <dockerhub_ID>/mymodified:latest

20) After this, you can pull the image from anywhere using this command

docker pull <dockerhub_ID>/mymodified

Vous aimerez peut-être aussi