Home
About
Resume
Projects
Links
Blog
Back to Contents
# Docker #### Installation (Using the repository) ##### Set up the repository 1\. Update the `apt` package index and install packages to allow `apt` to use a repository over HTTPS: ```bash sudo apt-get update sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg \ lsb-release ``` 2\. Add Docker’s official GPG key: ```bash curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg ``` 3\. Use the following command to set up the stable repository. To add the `nightly` or `test` repository, add the word nightly or test (or both) after the word `stable` in the commands below. ```bash echo \ "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null ``` ##### Install Docker Engine ```bash sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io ``` #### Usage Build an image ```bash docker build /dir/with/Dockerfile ``` Build an image with tag `-t` ```bash docker build -t tagName:version /dir/with/Dockerfile ``` Run a container ```bash docker run ubuntu ``` Run a container with interactive terminal `-it` ```bash docker run -it ubuntu ``` Run a container and removing itself after exit `--rm` ```bash docker run -it --rm ubuntu ``` Map TCP port in the container to port on the Docker host `-p` ```bash # Mapping host's port 8080 to container's port 80 docker run -it --rm -p 8080:80 ubuntu # Or multiple ports: mapping host's port 8080 and 2222 to container's port 80 and 22 docker run -it --rm -p 8080:80 -p 2222:22 ubuntu ``` Bind a volumn to the container from the Docker host ```bash docker run -it -v /host/path:/container/path ubuntu ``` #### Source **Documentation link**: [Docker docs](https://docs.docker.com/) **Docker CLI Reference**: [CLI Reference](https://docs.docker.com/engine/reference/run/)
Previous Post:
Markdown Syntax
Next Post:
Linux sendmail
Loading