💾 Archived View for gem.arisamiga.rocks › post › docker.gmi captured on 2023-07-22 at 16:38:13. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-04-26)
-=-=-=-=-=-=-
Docker is a tool that allows you to run applications in a containerized environment. It is a great tool for developers and sysadmins as it allows you to run applications in a sandboxed environment that is isolated from the host system. This allows you to run multiple applications in the same system without having to worry about conflicts between them.
Docker allows you to run an application in something called a "Container" which is an environment that is isolated from the host system. It is especially useful in cases where you need to have libraries or packages with different versions in the same system.
Docker is started by creating a Dockerfile which is a file that contains the instructions for building the container. The Dockerfile is then used to build the container which is then run by the Docker daemon. *(The Docker daemon is a service that runs in the background and is responsible for running the containers.)*
# syntax=docker/dockerfile:1 FROM node:12-alpine RUN apk add --no-cache python2 g++ make WORKDIR /app COPY . . RUN yarn install --production CMD ["node", "src/index.js"] EXPOSE 3000
Instead of a Dockerfile, you are able to also use a Docker image which is a pre-built container that you can use. Each image is made for specific purposes and is usually made by the community at
When a container is run using
it is then given a name and a unique ID. The name is used to identify the container and the ID is used to identify the container in the Docker daemon. By also using the
flag, the container is run in the background and is not attached to the terminal.
You can look at running containers using
and you can look at all containers using
which will show even exited ones.
Here are some of the most common commands that you will use when working with Docker.
The
command is used to run a container. It takes the name of the image that you want to run as an argument. You can also specify the name of the container using the `--name` flag. If you don't specify a name Docker will generate a random name for you.
docker run --name my-container my-image
The
command is used to list running containers. You can also use the `-a` flag to list all containers.
docker ps
The
command is used to stop a running container. It takes the name of the container as an argument.
docker stop my-container
The
command is used to start a stopped container. It takes the name of the container as an argument.
docker start my-container
The
command is used to remove a container. It takes the name of the container as an argument.
docker rm my-container
The
command is used to execute a command in a running container. It takes the name of the container as an argument and the command that you want to execute.
docker exec my-container ls
The
command is used to build a container from a Dockerfile. It takes the path to the Dockerfile as an argument.
docker build .
The
command is used to pull an image from Docker Hub. It takes the name of the image as an argument.
docker pull my-image
The
command is used to push an image to Docker Hub. It takes the name of the image as an argument.
docker push my-image
Docker is a pretty amazing tool to use and is especially useful when working with multiple applications and I couldn't recommend it enough.
Here is also an amazing Tutorial by Programming with Mosh that you can watch to learn more about Docker!
{{< youtube pTFZFxd4hOI >}}