others-How to print docker command line fully?
1. Purpose
In this post, I would demo how to print docker command line fully(not partially or truncated). Because sometimes , When we run the following command to check what container is running:
[root@kube-bswen ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1d2b528d4670 kong:latest "/docker-entrypoint.…" 2 weeks ago Up 8 minutes (healthy) 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp, 127.0.0.1:8001->8001/tcp, 0.0.0.0:8443->8443/tcp, :::8443->8443/tcp, 127.0.0.1:8444->8444/tcp kong
If we want to see the COMMAND
of the container, what we got is:
"/docker-entrypoint.…"
The COMMAND
of the container is truncated, and displayed partially, But we want to see the full command of the container. How to achieve this?
2. The solution
2.1 The tool to show the full docker command
We can use runlike
tool to show the full docker command like this:
[root@kube-bswen ~]# docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro \
> assaflavie/runlike kong
Unable to find image 'assaflavie/runlike:latest' locally
latest: Pulling from assaflavie/runlike
a0d0a0d46f8b: Already exists
14df950e5a79: Pull complete
86a31cc9e913: Pull complete
c6e88c3a8cca: Pull complete
843e00801cfc: Pull complete
8c7a43c10170: Pull complete
1b52f4e484f7: Pull complete
d2414af5b173: Pull complete
e784d6354f86: Pull complete
90bffe34dc9b: Pull complete
616b184e3902: Pull complete
Digest: sha256:a213a7d8e2a26ef0167b5d9a8d71c799cbb1fd52e350dbb69558ba3853a61889
Status: Downloaded newer image for assaflavie/runlike:latest
docker run --name=kong --hostname=1d2b528d4670 --user=kong --env=KONG_PG_USER=kong --env=KONG_ADMIN_ACCESS_LOG=/dev/stdout --env=KONG_CASSANDRA_CONTACT_POINTS=kong-database --env=KONG_PROXY_ACCESS_LOG=/dev/stdout --env=KONG_PROXY_ERROR_LOG=/dev/stderr --env=KONG_ADMIN_ERROR_LOG=/dev/stderr --env='KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl' --env=KONG_DATABASE=postgres --env=KONG_PG_HOST=kong-database --env=KONG_PG_PASSWORD=kong --env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --env=ASSET=ce --env=KONG_VERSION=2.6.0 --env=KONG_AMD64_SHA=43fb5f27185e274e22b4a36b93b1b7e27afe94b9fd2efbe4ec69b8ed8a9e5902 --env=KONG_ARM64_SHA=a057eaa6d10ecf49443ec0cac6e1b70a62ee357a777e0e169c780e18fd5c5544 --network=kong-net -p 8000:8000 -p 127.0.0.1:8001:8001 -p 8443:8443 -p 127.0.0.1:8444:8444 --restart=no --label='maintainer=Kong <[email protected]>' --runtime=runc --detach=true kong:latest kong docker-start
You can see that the full COMMAND
of the docker container is as follows:
docker run --name=kong --hostname=1d2b528d4670 --user=kong --env=KONG_PG_USER=kong --env=KONG_ADMIN_ACCESS_LOG=/dev/stdout --env=KONG_CASSANDRA_CONTACT_POINTS=kong-database --env=KONG_PROXY_ACCESS_LOG=/dev/stdout --env=KONG_PROXY_ERROR_LOG=/dev/stderr --env=KONG_ADMIN_ERROR_LOG=/dev/stderr --env='KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl' --env=KONG_DATABASE=postgres --env=KONG_PG_HOST=kong-database --env=KONG_PG_PASSWORD=kong --env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --env=ASSET=ce --env=KONG_VERSION=2.6.0 --env=KONG_AMD64_SHA=43fb5f27185e274e22b4a36b93b1b7e27afe94b9fd2efbe4ec69b8ed8a9e5902 --env=KONG_ARM64_SHA=a057eaa6d10ecf49443ec0cac6e1b70a62ee357a777e0e169c780e18fd5c5544 --network=kong-net -p 8000:8000 -p 127.0.0.1:8001:8001 -p 8443:8443 -p 127.0.0.1:8444:8444 --restart=no --label='maintainer=Kong <[email protected]>' --runtime=runc --detach=true kong:latest kong docker-start
The magic is caused by this command :
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro assaflavie/runlike kong
It just run a tool named runlike
against container named kong
, to print its full command to the console.
2.2 What is the runlike
tool?
Runlike
is just a command line tool to outputs the command of another docker container, along with all those options (ports, links, volumes, …). It’s a real time saver for those that normally deploy their docker containers via some CM tool like Ansible/Chef and then find themselves needing to manually re-run some container.
You can just run the runlike
tool as follows:
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro assaflavie/runlike <container-name>
Or to make an alias of it as follows:
alias runlike="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock assaflavie/runlike"
then use it :
runlike <container-name>
3. Summary
In this post, I demonstrated how to print the full COMMAND
of a docker container, the key point is use a right tool named runlike
, it’s a simple but useful command line tool . That’s it, thanks for your reading.