Thursday, September 24, 2020

How to Create a Basic Docker Container

 How to create a basic Docker container


Step 1: install docker in your pc, laptop or vm.

# sudo apt-get install docker.io

# sudo systemctl start docker

# sudo systemctl enable docker

Step 2: create a directory for testing purposes and access such folder

# mkdir Dockerfiles

# cd Dockerfiles

Step 3: Create a docker file and call it Dockerfile

# vi Dockerfile

# Specify the base image to use, gets downloaded automatically

FROM ubuntu

# Specify the maintainer and email address

MAINTAINER *** <***@gmail.com

RUN apt-get update

# Specify the command to run

CMD [#echo", "Hello guys...! from my first image"]

Step 4: Build your image and tag it

# sudo docker build -t myimage:1.0 .

    Sending build context to Docker daemon  2.048kB

    Step 1/4 : FROM ubuntu

     ---> bb0eaf4eee00

    Step 2/4 : MAINTAINER *** <***@gmail.com>

     ---> Using cache

     ---> 2c30cf6f43fb

    Step 3/4 : RUN apt-get update

     ---> Using cache

     ---> 832660e5cdc3

    Step 4/4 : CMD ["echo", "Hello guys...! from my first image"]

     ---> Using cache

     ---> 168e1047d6a4

    Successfully built 168e1047d6a4

    Successfully tagged myimage:1.0

Step 5: List the images available

$ sudo docker image list

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

myimage             1.0                 b6f0f1350590        2 minutes ago       95.8MB

ubuntu              latest              bb0eaf4eee00        8 days ago          72.9MB

Step 6: Run the image for testing purposes

# sudo docker run image_id

    Hello guys...! from my first image

Final Note: 

You can pull more images to play with using sudo docker pull image_name

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.