sagnikghoshcr7 / Docker-Commands

Some basic docker commands

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker Commands

docker

Creating and Running a Container from an Image

> docker run <image name>
docker run = docker create + docker start

Overriding Default Commands

> docker run <image name> command!
Example:
> docker run busybox hi there
> docker run busybox ls

image

List All Running Containers

> docker ps --all

List All Containers

> docker ps

Create a Container

> docker create <container id>

Start a Container

> docker start <container id>

Remove all Containers and Cache

> docker system prune

Get logs from a Container

> docker logs <container id>

Stop a Container

> docker stop <container id>

Kill a Container

> docker kill <container id>

Execute an Additional Command in a Container

> docker exec -it <container id> <command>
Example:
> docker exec -it 093bff89b3 redis-cli

image

-it can be written as -i -t
-i for input & -t for beautiful terminal output helpers

Getting a Command Prompt in a Container

> docker exec -it <container id> sh
Example:
> docker exec -it 093bff89b3 sh

Tagging an Image

> docker build -t <username>/<projectname>:<version or tag name> .
Then run it:
> docker run <username>/<projectname>      (default it takes >docker run <username>/<projectname>:latest)

image image

Copying Build Files

(It will be better to change working directory of the container first and then copy all build files to ignore folder name conflict issue)
> WORKDIR /usr/app
> COPY ./ ./

Container Port Mapping

> docker run -p <localhost port>:<container port> <imageid or imagename>

image

Docker-Compose

Start Container
> docker-compose up
Rebulid and Start Container
> docker-compose up --build
Launch in Background
> docker-compose up -d
Stop Containers
> docker-compose down
List All Running Containers in Docker-Compose file
> docker-compose ps

Docker build by other named Dockerfile

> docker build -f Dockerfile.dev .       (building by Dockerfile.dev file and -f for filename)

Bookmarking & Docker Volumes

image

About

Some basic docker commands

License:MIT License