Skip to content

Docker basic essential commands #10

@etture

Description

@etture
  • good to just alias docker="sudo docker" so that you don't have to type sudo every time

See

  • docker ps: see running containers
  • docker container ls -a: see all containers, even those that have stopped
  • docker images: see images on disk

Run

  • docker run <image_name>: run an image as a container
    • options
      • -p: expose a port inside the container to the host
        • e.g. -p 8123:8123
      • -v: mount a volume on the host to the container
        • e.g. -v /tmp:/usr
      • -d: run in detached mode
      • -ti: add terminal driver and run in interactive mode
      • -e: add environment variable
        • e.g. -e MYSQL_USER=etture
      • '--name`: designate a name for the container
        • e.g. --name my_container
    • complete example:
      sudo docker run -d -ti \
          -p 8123:8123 -v /tmp/usr \
          -e MYSQL_USER=etture \
          --name my_container \
          ubuntu:18.04 /bin/bash
  • docker exec: run a command in a running container
    • e.g. sudo docker exec -ti <container_name> /bin/bash
      • log in to the running container through an interactive shell

Remove

  • docker kill <container_name>: kill a container process
  • docker container rm <container_name>: remove a container from storage
  • docker rmi <image_name>: remove an image

Build

  • docker build -t <image_tag_name> .: build a new image using the Dockerfile in the current directory
  • docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]: change name of an existing image
  • docker push <image_tag_name>: push the image onto the Docker registry

Metadata

Metadata

Assignees

No one assigned

    Labels

    CloudCloud relatedDockerDocker relatedlinuxLinux related

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions