Docker User Guide
Introduction
Docker is an open-source platform designed to simplify the development, deployment, and running of applications. Docker uses container technology to achieve this goal. A container is a lightweight, standalone runtime environment.
Installing Docker
sudo apt-get update
sudo apt-get install -y docker.io docker-buildx
Basic Commands
Check Docker Version
sudo docker --version
Pull an Image
sudo docker pull <image_name>
Run a Container
sudo docker run -it <image_name>
List Running Containers
sudo docker ps
Stop a Container
sudo docker stop <container_id>
Building an Image
Create a Dockerfile
# Dockerfile
FROM harbor.spacemit.com/bianbu/bianbu:latest
RUN apt-get update && apt-get install -y python3
COPY . /app
WORKDIR /app
CMD ["python3", "app.py"]
Make sure to include a file named app.py
in your project directory, which will be executed as the entry point when the container starts.
# app.py
def main():
print("Hello, Docker!")
if __name__ == "__main__":
main()
Build the Image
sudo docker buildx build -t myapp --load -f Dockerfile .
Run
sudo docker run --rm myapp
You should see the output
Hello, Docker!
Managing Containers
View All Containers
docker ps -a
Remove a Container
docker rm <container_id>
Remove an Image
docker rmi <image_id>
Common Issues
How to Clean Up Unused Images and Containers?
docker system prune
How to View Container Logs?
docker logs <container_id>
How to Enter a Running Container?
docker exec -it <container_id> /bin/bash