Sie sind auf Seite 1von 7

DevOps www.edureka.

co/devops

Module 5: Docker Commands & Use


Cases
Assignment Solution

© Brain4ce Education Solutions Pvt. Ltd.


Module 5: Docker Commands & Use Cases www.edureka.co/devops

Module 5: Assignment Solution

1.Create Custom image from docker file.


Step 1: Create a directory called 'custom' and change to it. In this directory, create an
empty file called "Dockerfile".
Run command: mkdir custom

Step 2: Edit the "Dockerfile" created in above. This configuration file should be written to
perform the following actions:

 Use the base Centos 6 Latest version image from the public repository
 Identify you and your email address as the author and maintainer of this image
 Update the base OS after initial import of the image
 Install the Open-SSH Server
 Install Apache Web Server
 Expose ports 22 and 80 to support the services installed

Output:

©Brain4ce Education Solutions Pvt. Ltd Page 1


Module 5: Docker Commands & Use Cases www.edureka.co/devops

Step 3: Build the custom image from the 'Dockerfile' as created above. Name/tag this
new image as "mycustomimg/withservices:v1". Once the image is built, verify the image
appears in your list
Run command on your terminal : sudo docker build -t mycustomimg/withservices:v1 .
You will get output like this

2.Managing containers
Step 1: Create a container from the base image for the latest version of Ubuntu available
(if you do not have an Ubuntu base image installed locally, pull the latest one down for
your local repository). The container should be started in interactive mode attached to
the current terminal and running the bash shell. Once running, shut the container down
by exiting.
Run the command: sudo docker pull ubuntu:latest

©Brain4ce Education Solutions Pvt. Ltd Page 2


Module 5: Docker Commands & Use Cases www.edureka.co/devops

Run commands:sudo docker run -it ubuntu:latest /bin/bash


exit
Your Output would look like this:

Step 2: Run the appropriate Docker command to get the name of the previously run
container. Issue the appropriate command to restart the container that you obtained the
name of. Do NOT create a new container, restart the one we just used.
Run the following commands in your terminal:
sudo docker ps -a
sudo docker restart <docker image name as highlighted in the screenshot>
sudo docker ps

Step 3: Stop the container. Remove that container from the system completely using the
appropriate command.
Run the following commands:
sudo docker stop <docker image name>
sudo docker ps
sudo docker ps -a
sudo docker rm <docker image name>
sudo docker ps -a
Final output would look like this.

©Brain4ce Education Solutions Pvt. Ltd Page 3


Module 5: Docker Commands & Use Cases www.edureka.co/devops

Step 4: Create (not run) a container called "my_container", create it with parameters that
will allow it to run interactively and attached to the local console running the bash shell.
Verify that the container is not running.
Run command: sudo docker create -it --name="my_container" ubuntu:latest
/bin/bash
Your output screen will look like this.

Step 5: Start the container and again, verify the container is running. Run the appropriate
command to attach your session to the running container so you are logged into the
shell.
Run the following commands:
 sudo docker start my_container
 sudo docker attach my_container
Your output will look like this.

3. Add external contents to containers.


Step 1: Create a directory in your 'user' home directory called 'docker'. Within that
directory, create another directory called 'mydata'. Within that directory, create a file
called 'mydata.txt' containing any text message you want.
Your output will look like this

©Brain4ce Education Solutions Pvt. Ltd Page 4


Module 5: Docker Commands & Use Cases www.edureka.co/devops

Step 2: Create a docker container name 'local_vol' from the 'centos:6' image. The
container should be created in interactive mode, attached to the current terminal and
running the bash shell. Finally create the container with a volume (or directory) called
'containerdata' so that the system will automatically create the directory/mount when
the container starts.
Run command: sudo docker run -it --name="local_vol" -v /containerdata
centos:6 /bin/bash
Your output will look like this.

Step 3: List the filesystems within the container, specifically looking for the
volume/directory that was added to the container during creation.
Run the following commands:
o df -h
o ls -al /containerdata/
Your Output screen will look like this

©Brain4ce Education Solutions Pvt. Ltd Page 5


Module 5: Docker Commands & Use Cases www.edureka.co/devops

Step 4: Exit the container. This time, create another container called 'remote_vol' with
the same container configuration except when creating the volume in the container, link
the volume name 'mydata' to the underlying host directory structure created .

©Brain4ce Education Solutions Pvt. Ltd Page 6

Das könnte Ihnen auch gefallen