Starting Docker Containers¶
Sell It¶
Docker packages your software and all of its dependencies into portable containers that run the same way on laptops, servers, or the cloud. Instead of configuring each machine manually, you capture the environment once and share it with collaborators.
Show It¶
A simple Dockerfile defines an environment. Each instruction adds a layer to
the final image so it can be rebuilt or modified easily:
FROM python:3.11-slim
COPY . /app
RUN pip install -r requirements.txt
Do It¶
- Install Docker. Download Docker Desktop or the Docker Engine for your operating system from docker.com.
- Create a project. Make a folder with a
Dockerfilelike the example above or choose an existing image from Docker Hub. - Build the image. From the folder run
docker build -t myimage .to turn theDockerfileinto a reusable image. - Run the container. Launch it with
docker run -it myimage /bin/bashto open a shell inside the container. - Share it. Tag and push the image to a registry such as Docker Hub with
docker tag myimage myuser/myimagefollowed bydocker push myuser/myimage.
Review It¶
Use docker ps -a to list containers and docker images to see available
images. Remove test containers with docker rm and clean up images with
docker rmi when you're done.