Kanngongkanngoen

Docker for Development: Images, Containers, Compose, and Volumes

💡 Key takeaways

Docker packages an application environment in containers. This guide introduces images, containers, Dockerfiles, Compose, ports, and persistent volumes.

Docker packages an application and its runtime dependencies into images that can be run as containers. Unlike a traditional virtual machine, a container shares the host operating-system kernel while keeping application processes and files isolated. This can make development environments more repeatable across machines.

Images and containers

An image is a reusable template; a container is a running instance created from an image. Docker Desktop bundles tools for many desktop workflows. After installing the version appropriate for your operating system, docker -v can confirm that the CLI is available.

Try the public test image with docker pull hello-world, list local images with docker images, and run it with docker run hello-world. Docker downloads an image if needed and starts a container from it.

Build an image and publish a port

A Dockerfile describes how to build an image. Common instructions include FROM for a base image, WORKDIR for a working directory, COPY for application files, RUN for build-time commands, and CMD for the default start command. Build the current directory with docker build -t my-app .. A command such as docker run -p 8080:80 my-app maps host port 8080 to port 80 in the container.

Compose and persistent data

Compose describes related services in a YAML file, such as an application and a development database. Start them in the background with docker compose up -d and stop the project with docker compose down (older installations may use the separate docker-compose command). A Node.js application can connect to MySQL through a client library such as mysql2; keep passwords in local environment configuration and never commit production credentials.

Volumes keep data outside a container’s writable layer. Create and list them with docker volume create my-volume and docker volume ls; remove a volume with docker volume rm my-volume only when its data is no longer needed. For debugging, docker exec -it <container_id> sh opens a shell when the image provides one; not every image includes Bash.

Commands and Desktop features can change across Docker versions. Check current Docker documentation before using examples in a production environment, and avoid exposing database ports or storing sensitive data in disposable development containers.

Contact

For questions about the site, use the contact option below.

Contact on LINE

LINE contact QR code

Video and references

KGK

Kanngongkanngoen Editorial Team

We create clear educational content about personal finance, investing, and debt management, with an emphasis on accuracy and transparency.