95 posts tagged


Jun 11, 2020, 10:08

Centos 7 docker install

yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce.x86_64
systemctl start docker
systemctl enable docker

in case you do this under unprivileged used don't forget to add permission to the docker.sock

sudo groupadd docker
 sudo usermod -aG docker $USER
cd /var/lib/docker/containers && find . -type f -name *-json.log | xargs truncate -s0

install jq to the system with

apt-get install -y jq

or respective yum command

docker inspect container_name| jq ".[]|.Config.Env"
  1. Configure a role for EC2 instance with permissions to write to the CloudWatch.
  2. Assign that role to EC2 instance with docker.
  3. Open CloudWatch and create docker-logs logging group.
  4. Login into EC2 node and create file
  "log-driver": "awslogs",
  "log-opts": {
   "awslogs-group": "docker-logs"
  1. Restart docker with
systemctl restart docker

That's it.

  1. Go to the CloudWatch group and check logs, everything should be there :)

put this in .zshrc if you want to update `kube/config` with new port from kind container

kupdate() {
DOCKER_ID=`docker ps -a | awk '/kind-control-plane/{print $1}'`
PORT=`docker inspect ${DOCKER_ID} | jq -r '.[0].NetworkSettings.Ports["6443/tcp"][0].HostPort'`
kubectl config set clusters.kind-kind.server${PORT}
echo "port set to ${PORT}"

use your container name instead of kind-control-plane

docker start `docker ps -a | awk '/kind-control-plane/{print $1}'`
docker images -f reference=myimage -q | xargs docker rmi -f

put your image name w/o tags instread of myimage

core@coreos04itpremumlocalbak ~ $ docker ps -a -f name=redmine
CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS               NAMES
5c4c2c13eb0b        sameersbn/redmine:3.4.2   «/sbin/entrypoint.sh…»   14 months ago       Up 6 days           80/tcp, 443/tcp     redmine_redmine_1
ec9532ae1b24        sameersbn/postgresql      «/sbin/entrypoint.sh»    14 months ago       Up 6 days           5432/tcp            redmine_postgresql_1
core@coreos04itpremumlocalbak ~ $ docker ps -a -f name=redmine -q | xargs docker start
docker images | grep myname | cut -d' ' -f9 | xargs docker rmi -f

This oneliner will query for last 5 containers and removes them.

docker ps -a -n 5 -q | xargs docker rm

It is useful when you have dangling containers after failed builds

Afterward, you can launch image cleanup because you won't be tied with stopped containers.

docker rmi `docker images -qf dangling=true`
Ctrl + ↓ Earlier