Library › Servers & deployment

Free guide

Docker for Beginners

Package your application and everything it needs. Docker runs applications inside containers. Instead of: "Works on my computer." you can package the application with its environment.

2 min readFor developers and IT and support staff

Package your application and everything it needs.

Docker runs applications inside containers.

Instead of:

"Works on my computer."

you can package the application with its environment.


1. Check Docker

docker --version

2. Run a Container

docker run nginx

Docker downloads the image if necessary and starts a container.

Run it in the background:

docker run -d nginx

-d = detached.


3. See Running Containers

docker ps

See all containers, including stopped ones:

docker ps -a

4. Stop a Container

docker stop CONTAINER_ID

Start it again:

docker start CONTAINER_ID

5. Remove a Container

docker rm CONTAINER_ID

6. Images vs Containers

This distinction is important.

Image

Blueprint

Container

Running instance of that blueprint

For example:

nginx image
    ↓
nginx container

7. See Images

docker images

Remove an image:

docker rmi IMAGE_ID

8. View Container Logs

docker logs CONTAINER_ID

Follow the logs:

docker logs -f CONTAINER_ID

This is one of the most useful Docker commands when debugging.


9. Run a Container with a Port

A container might listen on port 80.

Expose it on your machine:

docker run -d -p 8080:80 nginx

Think:

Your machine : 8080
        ↓
Container : 80

Then visit:

http://localhost:8080

10. Docker Compose

When an application needs several services:

Application
Database
Redis
etc.

Docker Compose lets you define them together.

Start:

docker compose up -d

Stop:

docker compose down

See services:

docker compose ps

View logs:

docker compose logs

The Commands to Remember

What you wantCommand
Check Dockerdocker --version
Run containerdocker run
Running containersdocker ps
All containersdocker ps -a
Stopdocker stop
Startdocker start
Remove containerdocker rm
Imagesdocker images
Remove imagedocker rmi
Logsdocker logs
Port mappingdocker run -p
Start Composedocker compose up -d
Stop Composedocker compose down

Remember

Docker Image
     ↓
Docker Container
     ↓
Your Application

And for multi-service applications:

docker compose up -d

is often where the magic starts.