Run CentOS 8 in a docker container

Run CentOS 8 in a docker container

 

Step 1 : Download CentOS 8 docker image

 
You can download the CentOS 8 image using Docker pull command. Run the below command to pull CentOS 8 image from docker hub. Docker hub is a place where pre built images are stored. Docker pull command will download the pre built images to your local.

docker pull centos:centos8
 

root@myserver:~# docker pull centos:centos8
centos8: Pulling from library/centos
3c72a8ed6814: Pull complete
Digest: sha256:76d24f3ba3317fa945743bb3746fbaf3a0b752f10b10376960de01da70685
Status: Downloaded newer image for centos:centos8

 
Run the command ‘docker images’ to list all the images.
 
 

Step 2 : Run the CentOS 8 container using docker run command

 
Docker run command Usage : docker run [OPTIONS] IMAGE [COMMAND] [ARG…]

Execute the below command to Run CentOS 8 in a docker container.

To run interactively :
 

docker run –name centos8server -it centos:centos8 /bin/bash

 
To run in detached mode :
 

docker run –name centos8server -d centos:centos8 /bin/bash

 
-t = Allocate a pseudo-TTY

-p = To publish container’s port to host

-h = Use -h to set hostname for the container

-v = use -v to mount volume

 

root@myserver:~# docker run –name centos8server -d centos:centos8 /bin/bash
3b739ad18fe7c98779cbc5a11b3eb74ca2dd64ba7ce94877dd598a979f061886
root@myserver:~#

# docker run –name centos8server2 -it centos:centos8 /bin/bash
[root@90436ced45cd /]#

 
 

Step 3 : Run ‘Docker ps -a’ command to list all the containers

 
 

root@myserver:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90436ced45cd centos:centos8 “/bin/bash” About a minute ago Exited (0) 45 seconds ago centos8server