How to create Docker Images and Containers || Docker Creations

12 May 2021

blog details

How to create Docker Images and Containers || Docker Creations

By: RSDigitech | Published At : 12 May 2021    


How to create Docker images & containers:

To create docker images and containers soon, follow the below-listed commands, steps, and requirements to create a docker file, docker image, and the container.

Requirements:

  • Any virtual machine
  •  A user account with root permissions
  •  Install Docker on the machine.


Stage 1: Create a Docker file:

Create a new directory by using mkdir

~# mkdir myimages

Now, change the directory into my images.

~# cd myimages/

Use the touch command to create an empty Docker file.

# touch Docker file

Now, enter the below content in that file.

 apt get update

Stage 2: Create a Docker image:

Build the image by using the Docker file with the tag name at the present location.

docker build

We can verify the Docker image now.

verify the docker image

To delete a specific image.

image

For deleting all images at a time.

# docker rmi $ (docker images -q) -f

To know your image id.

# docker images -q

 Note:If you want to remove images, you must remove containers first.

Stage 3: Create a Docker Container:

To create a new container with the base image using the following command.

# docker run -name <name of the container> -d -p 8081:8080 <image_name>

docker run container

Now, the Container output will be displayed like this.

container output

To list out the running containers, perform the below commands:

running containers

 To remove a specific container.

remove container

To remove all the containers at a time.

remove all containers

To enter into a running container.

# docker exec -it <containerID> /bin/bash

We can start and stop the containers by using the following commands:

# docker start <ContainerID>

# docker stop <ContainerID>

Technologywe use

  • PHP
  • Angular
  • Android
  • Laravel
  • Salesforce
  • Tibco
  • Mulesoft