How to show the run command of a docker container

2019-01-21 01:28发布

I use a third party GUI (Synology Docker package) to setup a docker container. However, it's limitation makes me need to run the container from the command line. (I want to map another host ip to bind the port)

Now, since there are lots of settings that already done, I would like to retrieve the original run command that start this container, then I can change the port mapping port to new one. eg. "docker run -p 80:8080 gitlab"

I can't find the way to do so, event use "docker inspect", no such information provided.

Please provide some advice to solve this problem.

标签: docker
10条回答
闹够了就滚
2楼-- · 2019-01-21 02:00

If you do not want to install anything into your current running Docker server setup, you can simply execute (replace $CONTAINER_NAME with the container name you want to have the run arguments):

docker run -it--rm --volume /var/run/docker.sock:/var/run/docker.sock --privileged docker sh -c "apk add --no-cache nodejs nodejs-npm && npm i -g rekcod && rekcod $CONTAINER_NAME"

(for the rekcod method)

or

docker run -it--rm --volume /var/run/docker.sock:/var/run/docker.sock --privileged docker sh -c "apk add --no-cache py-pip && pip install runlike && runlike $CONTAINER_NAME"

(for the runlike method)

查看更多
别忘想泡老子
3楼-- · 2019-01-21 02:01

Currently it seems we have to go 'docker inspect ' and then manually recreate the run command.

I have found someone attempting to write a bash script to do this: https://gist.github.com/miracle2k/c85b7b077fdb8d54bc89

but it is incomplete and depends on jq.

查看更多
走好不送
4楼-- · 2019-01-21 02:02

Use following command to get the arguments for all containers docker inspect -f "{{.Name}} {{.Path}} {{.Args}}" $(docker ps -a -q)

查看更多
可以哭但决不认输i
5楼-- · 2019-01-21 02:04

I wrote a simple Node-based CLI tool to generate a docker run command from an existing container.

https://www.npmjs.com/package/rekcod

Here's an example:

$ npm i -g rekcod
$ rekcod redis_container

docker run -d --name redis_container --restart always -h a44159e148e1 \
--expose 6379/tcp -e PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
-e REDIS_VERSION=3.0.7 -e REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-3.0.7.tar.gz \
-e REDIS_DOWNLOAD_SHA1=e56b4b7e033ae8dbf311f9191cf6fdf3ae974d1c \
--entrypoint "/entrypoint.sh" redis "redis-server"

Also handles links and mounted volumes and other stuff.

Not super robust at the moment, but handles more than some of the other things mentioned, and it was more of what I was looking for.

查看更多
登录 后发表回答