Docker learning notes - 02

·

2 min read

1. Fix connect error

When first start Windows computer, may face an error when using docker commands

error during connect: This error may indicate that the docker daemon is not running.: Get "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/images/json": open //./pipe/docker_engine: The system cannot find the file specified.

Execute the following command in PowerShell to switch Docker daemon:

& 'C:\Program Files\Docker\Docker\DockerCli.exe' -SwitchDaemon

2. Image Commands

2.1 Displays the available commands:

docker image --help

2.2 Lists all the images:

docker image ls

2.3 Pulls an image from dockerhub:

docker image pull

docker image pull alpine

docker image pull alpine: 3.15

2.4 Build an existing image:

docker image build

2.5 Removes all unused images

docker image prune

2.6 Tags an image

docker image tag

2.7 Removes an image

docker image rm

3. Container Commands

3.1 See available commands

docker pull --help

3.2 Pulls a container

docker pull

3.3 Lists containers

docker container ls

3.4 Runs a container

docker run

3.5 Lists all containers

docker ps

3.6 Stop a container

docker stop

3.7 Start a container

docker start

3.8 Interact with a container

docker exec

3.9 Remove a stopped container

docker container rm

3.10 Removes all stopped containers

docker container prune

4. Dockerfile

4.1 Image and version

FROM

4.2 Adds file in build to the image

ADD

4.3 Same as ADD but limited to the project directory

COPY

4.4 Environment variables

ENV

4.5 Ports to expose

EXPOSE

4.6 Switch to a specific user

USER

4.7 Set the working directory

WORKDIR

4.8 Command that needs to be run on execution

CMD

4.9 Practice

Dockerfile:

FROM node:alpine

COPY . /app

WORKDIR /app

CMD ["node", "app.js"]

In PowerShell:

docker build -t docker-node .

docker run --rm docker-node