Master Docker Basics: From Images to Containers for Ops and Developers
This guide walks readers through Docker fundamentals, covering both operations and development perspectives, including installing Docker, managing images and containers, executing commands, connecting to running containers, building images from Dockerfiles, and deploying simple web applications on Linux and Windows environments.
Docker, written in Go and released in 2013, has become ubiquitous among developers and operations engineers; this article explains what Docker is and the differences between ops and dev perspectives.
From the ops perspective the main tasks include downloading images, running new containers, logging into containers, executing commands inside containers, and destroying containers.
From the dev perspective the focus is on pulling application code from GitHub, examining the Dockerfile, containerizing the application, and running it inside a container.
Ops Perspective
When Docker is installed two main components are involved: the Docker client and the Docker daemon (engine). The daemon implements the Docker Engine API. On Linux the client communicates with the daemon via the local UNIX socket /var/run/docker.sock; on Windows it uses the named pipe npipe:////./pipe/docker_engine. The command docker version can be used to verify that both client and daemon are running and can communicate.
1> docker version
2Client:
3 Version: 18.01.0-ce
4 API version: 1.35
5 Go version: go1.9.2
6 Git commit: 03596f5
7 Built: Wed Jan 10 20:11:05 2018
8 OS/Arch: linux/amd64
9 Experimental: false
10 Orchestrator: swarmIf the command fails on Linux, prepend sudo (e.g., sudo docker version) and add the current user to the docker group.
Images
A Docker image is an object that contains a filesystem and an application; it is similar to a VM template but represents an un‑running container. List images with docker image ls. If no images are present, the output will be empty.
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZEPull an image (e.g., ubuntu:latest on Linux or microsoft/powershell:nanoserver on Windows) and then list images again to see the newly downloaded image.
latest: Pulling from library/ubuntu
50aff78429b1: Pull complete
...
Status: Downloaded newer image for ubuntu:latestEach image has a unique ID that can be used to reference it.
Containers
Run a container from an image with docker container run. Example for Linux:
$ docker container run -it ubuntu:latest /bin/bash
root@6dc20d508db0:/#Example for Windows:
> docker container run -it microsoft/powershell:nanoserver pwsh.exe
Windows PowerShell
PS C:\>The -it flag starts an interactive terminal inside the container.
Inside the container you can list processes with ps -elf (Linux) or ps (Windows). Linux containers typically show only a few processes (e.g., /bin/bash and the ps command itself).
root@6dc20d508db0:/# ps -elf
F S UID PID PPID NI ADDR SZ WCHAN STIME TTY TIME CMD
...Exit the container without stopping it by pressing Ctrl‑P Q. The container continues to run in the background.
List running containers with docker container ls. To stop and remove a container use docker container stop <name> and docker container rm <name>. Adding the -a flag to docker container ls shows all containers, including stopped ones.
Dev Perspective
Containerizing an application starts with a Dockerfile that describes how to build an image. Example Dockerfile for a simple Node.js app:
FROM alpine
LABEL maintainer="[email protected]"
RUN apk add --update nodejs nodejs-npm
COPY . /src
WORKDIR /src
RUN npm install
EXPOSE 8080
ENTRYPOINT ["node", "./app.js"]Build the image with docker image build -t test:latest .. After a successful build the new image appears in docker image ls.
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
Test latest f154cb3ddbd4 1 minute ago 55.6MBRun the container in detached mode, give it a name, and publish port 8080:
$ docker container run -d \
--name web1 \
--publish 8080:8080 \
test:latestOpen a web browser and navigate to http://<docker‑host>:8080 (or localhost:8080 on Windows/macOS) to see the application’s web page.
Summary
The ops section covered downloading images, starting containers, entering containers, inspecting processes, and cleaning up containers. The dev section demonstrated pulling source code, writing a Dockerfile, building an image, and running the containerized application.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
