Docker Quick Start Guide and Frontend Project Containerization
This tutorial provides a comprehensive Docker quick‑start for Linux, covering installation, essential commands, container lifecycle, image management, and step‑by‑step containerization of a frontend project with Dockerfile creation, image building, container deployment, registry push, and common troubleshooting FAQs.
Docker Quick Start
1.1 Install Docker (Linux)
Yum repository: https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo (replace the URL in the repo file for faster download).
:%s/download.docker.com/mirrors.tuna.tsinghua.edu.cn\/docker-ce/gDocker version 19.03.12, build 48a66213fe
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
dnf list docker-ce
dnf install docker-ce --nobest -y
systemctl start docker
systemctl enable docker
docker -v1.2 Docker Commands
info – display system information
# docker info
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.09.1
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfsversion – show Docker version information
# docker version
Client: Docker Engine - Community
Version: 19.03.12
API version: 1.39
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:46:54 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.1
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 4c52b90
Built: Wed Jan 9 19:06:30 2019
OS/Arch: linux/amd64
Experimental: falseContainer Lifecycle
search – find images docker search hello-world pull – download an image from Docker Hub
# docker pull hello-world
Using default tag: latest
... (output omitted for brevity)images – list local images
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 6 months ago 13.3kBrun – start a container
-i : interactive mode
-t : allocate a pseudo‑TTY
-d : run in background
--name : assign a name to the container
-p : port binding
docker run [options] IMAGE
docker run hello-world
docker run --name mywebserver -it nginx
# docker run --name mywebserver -itd nginx
... (container ID output)ps – list container processes (add -a to show all)
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# docker ps -a
... (output showing stopped containers)rm – remove a container (use -f to force)
# docker rm mywebserver
mywebserver
# docker rm 01bdedde3725
01bdedde3725start / restart / stop – control container state
# docker stop mywebserver
mywebserver
# docker start mywebserver
mywebserver
# docker restart mywebserver
mywebserverstats – display resource usage
# docker stats mywebserver
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
8d485b358cc6 mywebserver 0.00% 2.309MiB / 3.664GiB 0.06% 3.44kB / 0B 0B / 0B 2logs – view container logs (add -f for live streaming)
# docker logs -f mywebserver
... (log output)pause / unpause – suspend and resume a container
# docker pause mywebserver
mywebserver
# docker unpause mywebserver
mywebserverrename – rename a container
# docker rename mywebserver webserver
# docker ps
... (container now named webserver)inspect – show detailed container information (JSON output omitted for brevity)
# docker inspect webserver
[ { "Id": "8d485b...", "Created": "2020-07-09T01:55:08.20199984Z", ... } ]kill – terminate a container process
# docker kill webserver
webservertop – view processes inside a container
# docker top webserver
UID PID PPID C STIME TTY TIME CMD
root 7153 7136 0 22:30 pts/0 00:00:00 nginx: master process nginx -g daemon off;exec – run a command inside a running container
# docker exec -it webserver bash
root@8d485b...:/# lsport – display port bindings
# docker port webserver
80/tcp -> 0.0.0.0:8000cp – copy files between host and container
# docker cp /etc/hosts webserver:/tmp
# docker exec -it webserver ls /tmp
hosts
# docker cp webserver:/tmp/hosts ./diff – show filesystem changes in a container
# docker diff webserver
C /etc
C /etc/nginx
... (list omitted)export / import – export a container's filesystem to a tar archive and import it as an image
# docker export -o test.tar webserver
# mkdir docker && mv test.tar docker/
# cd docker && tar xf test.tar
... (files listed)Image Operations
history – view image build history
# docker history nginx
IMAGE CREATED CREATED BY SIZE COMMENT
2622e6cca7eb 4 weeks ago /bin/sh -c #(nop) CMD ["nginx" "-g" ...] 0B
... (output truncated)login / logout – authenticate with Docker Hub
# docker login
Username: devopsvip
Password: ********
Login Succeeded
# docker logout
Removing login credentials for https://index.docker.io/v1/search / pull / images / tag / push / rmi – typical image workflow (examples shown for hello‑world and a custom image)
# docker search hello-world
# docker pull hello-world
# docker images
# docker tag hello-world devopsvip/docker:latest
# docker push devopsvip/docker:latest
# docker rmi devopsvip/docker:latestcommit – create a new image from a container's changes
# docker commit -a "devopsvipxx" -m "hhahh" webserver webserver:v1
sha256:d315f2bb4060build – build an image from a Dockerfile
# docker build .
# docker build -t webserver:v2 .
Successfully built d315f2bb4060
Successfully tagged webserver:v2load / save – load an image from a tar archive or save an image to a tar archive
# docker save -o webserver-v2.tar webserver:v2
# docker load -i webserver-v2.tar
Loaded image: webserver:v2create / update – create a stopped container and update its resources
# docker create --name webnewserver nginx
bbc81d2c7283
# docker start webnewserver
webnewserver
# docker update --memory 1G --memory-swap 1G webnewserverFrontend Project Containerization
1.1 Manual Deployment of Frontend Project
Install npm (CentOS 8 may prompt for installation) or manually install Node.js.
git clone https://github.com/dockersamples/node-bulletin-board
cd node-bulletin-board/bulletin-board-app
npm install
npm start
# Application runs on port 8080Access: http://192.168.1.105:8080/#
1.2 Deploy with Docker
Create a Dockerfile
FROM node:current-slim # base image
WORKDIR /usr/src/app # set working directory
COPY package.json . # copy package.json
RUN npm install # install dependencies
EXPOSE 8080 # expose port
CMD ["npm", "start"] # start the app
COPY . . # copy source codeBuild the image
docker build -t bulletinboard:1.0 .Run a container
# docker run -itd --name bb -p 8000:8080 bulletinboard:1.0Access the service on host port 8000.
Remove the container and image
docker stop bb
docker rm bb
docker rmi bulletinboard:1.01.3 Push Image to Registry
Tag and push the image to Docker Hub (repository name: bulletinboard)
# docker tag bulletinboard:1.0 devopsvip/bulletinboard:1.0
# docker push devopsvip/bulletinboard:1.0FAQ
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? Got permission denied while trying to connect to the Docker daemon socket ...
## Solution
# usermod -aG docker usera
# su - usera
# docker images docker: Error response from daemon: Conflict. The container name "/mywebserver" is already in use ...
## Solution
1. Use a different name: docker run --name mywebserver01 -it nginx
2. Remove the existing container: docker rm mywebserver Error response from daemon: Container 8d485b... is not running
## Solution
Start the container again before executing commands.How to expose nginx externally? Use -p host_port:container_port when running.
# docker run --name webserver -p 8000:80 -itd nginx
# curl 127.0.0.1:8000
... (HTML page output)How to register a Docker Hub account? (Screenshots omitted)
denied: requested access to the resource is denied
## Solution
docker loginHow to copy a local image to a remote machine?
# docker save -o webserver-v2.tar webserver:v2
# scp webserver-v2.tar [email protected]:/tmp/
# ssh [email protected]
# docker load -i /tmp/webserver-v2.tarFor more tutorials, follow DevOps Cloud Classroom.
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.
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
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.
