Skip to main content

Command Palette

Search for a command to run...

Docker Command Overview and Tips

Published
•2 min read•View as Markdown
Docker Command Overview and Tips

Overview of Your Command History

Updating and Installing Docker:

  • sudo apt update: Updates the package list.

  • sudo apt install docker-ce -y: Installs Docker Community Edition.

Starting and Enabling Docker:

  • sudo systemctl start docker: Starts the Docker service.

  • sudo systemctl enable docker: Ensures Docker starts on boot.

Managing Docker Containers:

  • docker run hello-world: Tests your Docker installation by running a simple container.

  • docker pull mysql:latest: Pulls the latest MySQL image.

  • docker run -d --name mysql-container -e MYSQL_ROOT_PASSWORD=6969 mysql:latest: Runs a MySQL container in detached mode with an environment variable for the root password.

  • docker ps and docker ps -a: Lists running containers and all containers (including stopped ones).

Viewing Logs:

  • docker logs <container_id>: Retrieves logs for a specific container (useful for debugging).

Executing Commands in Containers:

  • docker exec -it <container_id> /bin/bash: Opens a bash shell inside a running container, allowing you to interact with it.

Managing Docker Images:

  • docker images: Lists all downloaded images.

  • docker build -t counter-app .: Builds a Docker image from a Dockerfile in the current directory.

Cleaning Up:

  • docker rm <container_id>: Removes a stopped container.

  • docker kill <container_id>: Kills a running container.

Recommendations and Tips

Ensure Proper Command Syntax:

  • For the command docker build -t counter-app., it should be docker build -t counter-app . (with a space before the dot). The dot indicates the build context (the current directory).

Docker Logs Command:

  • When using docker logs, ensure you provide the correct container name or ID. If the container is named mysql-container, you should run:

      docker logs mysql-container