Master Docker Desktop: Pull Images, Run Containers, and Build Custom Dockerfiles
This guide walks you through deploying backend services with Docker Desktop, from installing Docker and pulling an Nginx image to configuring ports, volumes, and environment variables, then shows how to create and build a custom Dockerfile for persistent containerized applications.
Deploying backend services such as MySQL, Redis, or custom applications often requires repetitive installation of dependencies and environment configuration on each machine; missing a step can cause services to fail. Docker solves this by packaging the entire filesystem, dependencies, and configuration into a portable image that runs as an isolated container with its own filesystem, network ports, and environment.
After installing Docker Desktop from the official website, verify the docker command is available in the terminal. If the command is not in PATH, add the Docker binary directory (e.g., /usr/local/bin) or manually append $HOME/.docker/bin to PATH via Docker Settings → Advanced.
Docker Desktop provides a visual interface to manage images and containers. Use the Docker Hub tab to search for an image (e.g., nginx) and click Pull . After the image appears in the Images list, click Run and fill in the form:
Name : optional container name; Docker generates one if omitted.
Port mapping : map a host port (e.g., 80) to the container’s 80 port.
Volume : mount a host directory (e.g., /tmp/aaa) to /usr/share/nginx/html inside the container.
Environment variables : define key‑value pairs (e.g., KEY1=VALUE1).
Detach : run the container in the background ( -d).
The UI actions correspond to the following CLI commands:
docker pull nginx:latest docker run --name nginx-test2 -p 80:80 -v /tmp/aaa:/usr/share/nginx/html -e KEY1=VALUE1 -d nginx:latestKey flags: -p: port mapping -v: volume mount -e: environment variable -d: run in detached mode
Docker Desktop also visualizes common commands: docker ps (add -a to show all containers) docker images to list local images docker exec -it <container_id> /bin/bash for an interactive shell docker logs <container_id> to view logs docker inspect <container_id> for detailed metadata docker volume to manage data volumes
To create a custom image, write a Dockerfile that declares the build steps. Example:
FROM node:latest
WORKDIR /app
COPY . .
RUN npm install -g http-server
EXPOSE 8080
CMD ["http-server", "-p", "8080"]The instructions mean:
FROM : start from the official Node base image.
WORKDIR : set the working directory inside the image.
COPY : copy the current directory’s contents into the image.
RUN : install http-server globally.
EXPOSE : declare that the container will listen on port 8080.
CMD : the command executed when the container starts.
Save the file as Dockerfile and build the image: docker build -t aaa:ccc . Run the new image via Docker Desktop or CLI, specifying the same port and volume options as before. The container serves the static files from the mounted host directory.
When a VOLUME directive is declared in a Dockerfile, Docker automatically creates a persistent storage location. If you run a container without -v, Docker still mounts a temporary directory, ensuring data is not lost when the container stops. This is crucial for stateful services like MySQL; their official images include a VOLUME declaration to protect data even if the user forgets to specify a host mount.
In summary, Docker packages environments into images, which can be instantiated as containers with isolated filesystems, ports, and environment variables. Docker Desktop offers a visual way to pull images, configure containers, and manage volumes, while the underlying CLI commands provide the same functionality for headless servers. Building custom images with a Dockerfile gives you full control over the container’s contents and ensures data persistence through the VOLUME instruction.
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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
