💾 Archived View for gem.sdf.org › s.kaplan › cheatsheets › commandline-tools › docker.md captured on 2024-08-31 at 12:49:56.
⬅️ Previous capture (2023-09-08)
-=-=-=-=-=-=-
# Docker Cheatsheet ## Overview Docker is a platform for developing, shipping, and running applications in containers. ## Installation - [Docker Desktop for Mac](https://docs.docker.com/docker-for-mac/install/) - [Docker Desktop for Windows](https://docs.docker.com/docker-for-windows/install/) - [Docker Engine for Linux](https://docs.docker.com/engine/install/) ## Basic Usage 1. Create a `Dockerfile` in the root directory of your project. 2. Define the base image and any additional dependencies or configuration. 3. Build the Docker image using `docker build`. 4. Run the Docker container using `docker run`. ## Dockerfile Syntax
FROM python:3.7-slim
WORKDIR /app
COPY . /app
RUN pip install --trusted-host pypi.python.org -r requirements.txt
EXPOSE 80
ENV NAME World
CMD ["python", "app.py"]
- The `FROM` keyword specifies the base image to use. - The `WORKDIR` keyword sets the working directory for subsequent commands. - The `COPY` keyword copies files from the host to the container. - The `RUN` keyword executes a command in the container. - The `EXPOSE` keyword exposes a port for the container. - The `ENV` keyword sets an environment variable. - The `CMD` keyword specifies the default command to run when the container starts. ## Commands - `docker build`: Builds a Docker image from a Dockerfile. - `docker run`: Runs a Docker container from an image. - `docker ps`: Lists all running containers. - `docker stop`: Stops a running container. - `docker rm`: Removes a stopped container. - `docker rmi`: Removes an image. - `docker-compose`: Manages multi-container Docker applications. ## Resources - [Docker website](https://www.docker.com/) - [Docker documentation](https://docs.docker.com/) - [Docker Hub](https://hub.docker.com/)