Docker[2] | Run a Web App with Docker

Tuesday, Jul 13, 2021 | 2 minute read | Updated at Wednesday, Oct 12, 2022

@

Downloading image

In this scenario, you will create your very first container. To create a container, you need an image, which the container will be created from. Images are usually hosted somewhere in an accessible location called a Registry. The registry is a single place to manage Docker images. Users can create an account and push their own images to the registry.

Use the following command to search for a desired image in the registry: docker search loodse This will return a list of images belonging to the user loodse.

Once you know that the image you need exists in the registry, you can pull it to your local system to create containers from it. Execute the following to pull the image: docker pull loodse/demo-www  The docker pull command downloads the image from Docker Hub, which serves as the default registry for Docker. To see the list of downloaded images, run: docker images You should see loodse/demo-www entry in the list of images.

Creating a container

Now we have image downloaded and ready to use, we can create container using docker run -d loodse/demo-www. The -d flag instructs docker to create container and run it in background.
You can see list of running containers using docker ps. You can see an entry with loodse/demo-www string in IMAGE column. To interact with container you need CONTAINER ID which you can grab from first column.

Inspect running container

We can get details of running container using docker inspect command. You can use that command like docker inspect <CONTAINER ID>.
It gives you whole lot of information about running container including IP, MacAddress, Hostname etc.

List container

List all running container.
docker ps
The docker ps command only shows running containers by default. To see all containers, use the -a (or –all) flag:
docker ps -a
Let’s start a second webserver.
docker run -t -p 8080:80 loodse/demo-www
With docker ps you see now two running containers.
Use the second terminal:   docker ps -a
Terminate running container Stop the started container. The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL. Use the second terminal:  docker stop --time 5 <yourContainerId>
You can also restart your container, try:
docker restart <yourContainerId>
If you have e.g. an hanging container, it’s possible to send the SIGKILL signal directly. Try
docker kill <yourContainerId>

© 2025

Hello! Welcome!

This Website was created to keep notes