Docker[1] | Run First Container

Monday, Jul 12, 2021 | 2 minute read | Updated at Tuesday, Oct 11, 2022

@

Hello World

In your Docker environment, simply run this command:
docker run alpine echo hello world
- docker run starts a new container and executes a command. - alpine is a lightweight Linux distribution often used for containerized applications. - "hello world" is printed by executing the echo command inside the container.

Run an Apache in a Container

For interactive processes (like a shell), you must use docker run with -i and -t together in order to allocate a tty for the container process. -i and -t is often combined as -it.
To expose a container’s internal port, you can start the container with the -P or -p flag.

  • -P (uppercase) maps all exposed container ports to random ports on the host.
  • -p <host_port>:<container_port> (lowercase) maps a specific container port to a host port. Now, start a new Ubuntu container with an interactive shell and port 80 exposed: docker run -it -p 80:80 ubuntu
    Now, let’s install Apache inside the container:
    apt-get update && apt-get install -y apache2
    Start the Apache server:
    apache2ctl -DFOREGROUND
    Test access to the website bt navigating to: http://localhost:80

Stop the Container

To stop the process inside the container, use Ctrl+C (^C) Even after stopping, the container still exists on disk. To list all containers (running and stopped), use: docker ps -a
To delete all running and stopped container execute: docker rm $(docker ps -aq)
Check if the containers get deleted:
docker ps -a

© 2025

Hello! Welcome!

This Website was created to keep notes