---
# System prepended metadata

title: Docker

---

# Docker

## Docker command

### Docker container & Image

```
# run container
docker container run -p <<external port>>:<<internal port>> <<image>>

# run in background
docker container run -p <<external port>>:<<internal port>> --detach <<image>>

# run in background
docker container run -p <<external port>>:<<internal port>> --detach --name <<container name>> <<image>> 

# show running container
docker container ls 

# stop container
docker container stop <<container name|id>>

# start container
docker container start <<container name|id>>

# delete stopped container
docker container prune

# show all image
docker images 

# pull image from docker hub
docker image pull <<image name>> 

# run additional command in running container
docker container exec -it <<container name|id>>

# get logs from container
docker log <<container name|id>>

# performance stats for all containers
docker container stats

# see running process from a container
docker container top <<container name|id>>
```
### Network
```
# create new network
docker network create <<network name>>

# list all network
docker network ls

# inspect network
docker network inspect <<network id>>

# connect container with network
docker network connect <<network id>> <<container id>>
```
### Volume
```
# named volume
docker container run -d --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=True -v mysql-db:/var/lib/mysql mysql

# bind mount
docker container run -d --name nginx -p 80:80 -v $(pwd):/usr/share/nginx/html nginx
```

### Dockerfile & compose

```
# build image
docker image build -t custom-nginx .

# tag image
docker image tag nginx-html daniarwido/nginx-html

# login to docker hub
docker login

# push image to docker hub
docker image push <<image name>>


# docker compose
docker-compose up # start container
docker-compose up --build # rebuild image and run
docker-compose down # sop container
```

