Dockers and containers

docker container run – docker container run -t ubuntu top

we can use docker container run command to run a container with the Ubuntu image by using the top command.

The -t flag allocates a pseudo-TTY, which you need for the top command to work correctly.

docker container ls – list the containers

using this command we can get the ID of the running container that we just created.

docker container exec -it xxxxxxxxxxxxx bash

use this docker container exec command to enter the container’s namespaces with the bash process. Using docker container exec with bash is a common way to inspect a Docker container. After all use exit command to exit from container’s namespace.

ps -ef

use this command to inspect the running processes

PID is just one of the Linux namespaces that provides containers with isolation to system resources. Other Linux namespaces include:

MNT: Mount and unmount directories without affecting other namespaces.
NET: Containers have their own network stack.
IPC: Isolated interprocess communication mechanisms such as message queues.
User: Isolated view of users on the system.
UTC: Set hostname and domain name per container.

docker container run –detach –publish 8080:80 –name nginx nginx

using this command we can run an NGINX server by using the official NGINX image from the Docker Store

The –detach flag will run this container in the background

The publish flag publishes port 80 in the container (the default port for NGINX) by using port 8080 on your host. Remember that the NET namespace gives processes of the container their own network stack. The –publish flag is a feature that can expose networking through the container onto the host.

–name flag is the name of container