Docker useful commands
Testing environments on docker
If you are constantly testing/trying new software is cleaner and safer to do so in a new enviornment. For this docker is very handy.
Run a Debian container and enter it
docker run -p 3000:3000 -it debian:latest /bin/bash
apt update && apt upgrade -y
apt install -y git wget nodejs npm build-essential
If go is required:
wget https://go.dev/dl/go1.21.1.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.1.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
Other example. Run an aws cli:
docker run --rm -it --entrypoint /bin/sh --name aws-cli amazon/aws-cli
aws configure
Other useful enviornments for simpler tasks
docker run -it golang:latest /bin/bash
docker run -it node:latest /bin/bash
AWS
docker run -it debian:latest /bin/bash
apt update && apt upgrade -y && apt install -y curl unzip less && curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install
aws configure
a few random docker useful commands
docker build . -t mynewimage
docker run -d -t --name letsrock imagename
docker exec -it letsrock bash
1
docker images
docker ps
docker-compose up -d
docker-compose up -d mycontainer
To view space used by docker: docker system df
docker system prune -a
To delete all volumes using the following command:
docker volume rm $(docker volume ls -q)
View logs docker logs imagename -f
Create external network for traefik docker network create --driver=bridge --attachable --internal=false traefik_proxy
Output: 7aa05528d00064911164455c18d06a920885c1011fb1e9183d6f4ef437aae31f
docker stats
-
Some containers may not have bash installed. To add it add the following line to the Dockerfile
RUN apk update && apk add bash
. You can also just run from the command linedocker exec -it mycontainer apk update
anddocker exec -it mycontainer apk add bash
↩