docker container ls -q | \
xargs docker container inspect --format \
'{{ .Name }}: {{.HostConfig.RestartPolicy.Name}}'
Tag Archives: docker
docker list ip addresses
docker inspect --format='{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)
docker container show exposed ports
docker container ls --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}" -a
docker ubuntu systemctl in container
docker run \
--tty \
--privileged \
--volume /sys/fs/cgroup:/sys/fs/cgroup:ro \
robertdebock/ubuntu
docker bash autocompletion
cd /etc/bash_completion.d/
wget https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker
For docker-compose:
curl -L https://raw.githubusercontent.com/Yelp/docker-compose/master/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose
docker-compose latest version
VERSION=$(curl –silent https://api.github.com/repos/docker/compose/releases/latest | grep -Po ‘”tag_name”: “\K.*\d’)
curl -L https://github.com/docker/compose/releases/download/${VERSION}/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker remove dangling images
docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi
docker detach from running container
To detach the tty without exiting the shell, use the escape sequence Ctrl+P followed by Ctrl+Q. More details here.
Additional info from this source:
docker run -t -i → can be detached with ^P^Qand reattached with docker attach
docker run -i → cannot be detached with ^P^Q; will disrupt stdin
docker run → cannot be detached with ^P^Q; can SIGKILL client; can reattach with docker attach
redirect input into dockerfile
docker build -t myimage:latest -f- . <<EOF FROM centos CMD mkdir /app WORKDIR /app RUN echo "file contents" > file.txt EOF Sending build context to Docker daemon 16.43kB Step 1/4 : FROM centos ---> 470671670cac Step 2/4 : CMD mkdir /app ---> Using cache ---> cf9be82aca00 Step 3/4 : WORKDIR /app ---> Using cache ---> 24baea1f7712 Step 4/4 : RUN echo "file contents" > file.txt ---> Using cache ---> 61db761dc411 Successfully built 61db761dc411 Successfully tagged myimage:latest docker run --name ttt -ti -d --privileged=true myimage "/sbin/init" docker exec -it ttt cat '/app/file.txt' file contents
docker detach keep running
CTRL+p CTRL+q
Failed to connect to bus: Host is down
Use privileged if have problems with systemd inside docker:
docker run --name centos01.server -ti -d --privileged=true centos "/sbin/init"
centos 7 install docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io
systemctl start docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2020-02-18 12:33:55 EET; 12s ago
Docs: https://docs.docker.com
Main PID: 1708 (dockerd)
Tasks: 8
Memory: 44.2M
CGroup: /system.slice/docker.service
└─1708 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Feb 18 12:33:53 centos7.test.local dockerd[1708]: time="2020-02-18T12:33:53.665525062+02:00" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
Feb 18 12:33:53 centos7.test.local dockerd[1708]: time="2020-02-18T12:33:53.665553382+02:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0
Feb 18 12:33:53 centos7.test.local dockerd[1708]: time="2020-02-18T12:33:53.665569778+02:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Feb 18 12:33:54 centos7.test.local dockerd[1708]: time="2020-02-18T12:33:54.249825464+02:00" level=info msg="Loading containers: start."
Feb 18 12:33:54 centos7.test.local dockerd[1708]: time="2020-02-18T12:33:54.891677093+02:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set...rred IP address"
Feb 18 12:33:55 centos7.test.local dockerd[1708]: time="2020-02-18T12:33:55.220309512+02:00" level=info msg="Loading containers: done."
Feb 18 12:33:55 centos7.test.local dockerd[1708]: time="2020-02-18T12:33:55.249438236+02:00" level=info msg="Docker daemon" commit=369ce74a3c graphdriver(s)=overlay2 version=19.03.6
Feb 18 12:33:55 centos7.test.local dockerd[1708]: time="2020-02-18T12:33:55.249967901+02:00" level=info msg="Daemon has completed initialization"
Feb 18 12:33:55 centos7.test.local dockerd[1708]: time="2020-02-18T12:33:55.311906207+02:00" level=info msg="API listen on /var/run/docker.sock"
Feb 18 12:33:55 centos7.test.local systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
docker file stdout
cd /var/log/apache2
lrwxrwxrwx 1 root root 11 Feb 17 2018 access.log -> /dev/stdout
lrwxrwxrwx 1 root root 11 Feb 17 2018 error.log -> /dev/stderr
It means you can get logs records from host node:
tailf /var/log/messages
docker prestashop install
docker run -ti --name some-mysql2 --network prestashop-net -e MYSQL_ROOT_PASSWORD=admin -e MYSQL_DATABASE=prestashop -e MYSQL_ROOT_HOST=% -p 3308:3306 -d mysql:5.7
docker run -ti --name presta1 --network prestashop-net -e DB_SERVER=172.18.0.3 -e PS_DEV_MODE=true -e PS_INSTALL_AUTO=1 -p 8080:80 -d prestashop/prestashop:1.7-7.0
That will run auto install on presta1:
/bin/sh /tmp/docker_run.sh
php /var/www/html/install/index_cli.php –domain=172.18.0.4 –db_server=172.18.0.3:3306 –db_name=prestashop –db_user=root –db_password=admin –prefix=ps_ –firstname=John –lastname=Doe –password=prestashop_demo –[email protected] –language=en –country=gb –newsletter=0 –send_email=0
kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS (code=exited, status=255)
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS (code=exited, status=255)
journalctl -u kubelet
kubelet[25843]: F0310 21:08:58.395379 25843 server.go:189] failed to load Kubelet config file /var/lib/kubelet/config.yaml, error
kubelet.service: main process exited, code=exited, status=255/n/a
Fix:
kubeadm init
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using ‘kubeadm config images pull’
[kubelet-start] Writing kubelet environment file with flags to file “/var/lib/kubelet/kubeadm-flags.env”
[kubelet-start] Writing kubelet configuration to file “/var/lib/kubelet/config.yaml”
[kubelet-start] Activating the kubelet service
[certs] Using certificateDir folder “/etc/kubernetes/pki”
[certs] Generating “etcd/ca” certificate and key
[certs] Generating “etcd/server” certificate and key
…