Coder Social home page Coder Social logo

lavie / runlike Goto Github PK

View Code? Open in Web Editor NEW
1.9K 18.0 113.0 221 KB

Given an existing docker container, prints the command line necessary to run a copy of it.

License: Other

Python 84.01% Shell 11.47% Makefile 3.02% Dockerfile 1.49%
docker docker-container python

runlike's Introduction

"See this docker container? I wish I could run another one just like it,
but I'll be damned if I'm going to type all those command-line switches manually!"

This is what runlike does. You give it a docker container, it outputs the command line necessary to run another one just like it, along with all those pesky 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.

Usage

runlike <container-name>

This prints out what you need to run to get a similar container. You can do $(runlike container-name) to simply execute its output in one step.

-p breaks the command line down to nice, pretty lines. For example:

$ runlike -p redis

docker run \
    --name=redis \
    -e "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
    -e "REDIS_VERSION=2.8.9" \
    -e "REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-2.8.9.tar.gz" \
    -e "REDIS_DOWNLOAD_SHA1=003ccdc175816e0a751919cf508f1318e54aac1e" \
    -p 0.0.0.0:6379:6379/tcp \
    --detach=true \
    myrepo/redis:7860c450dbee9878d5215595b390b9be8fa94c89 \
    redis-server --slaveof 172.31.17.84 6379

Feeding it the output of docker inspect also works:

docker inspect <container-name> | runlike --stdin

--no-name will omit the container name from the output (to avoid collisions).

Run without installing

runlike is packaged as a Docker image: assaflavie/runlike.

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
    assaflavie/runlike YOUR-CONTAINER

You can also run it with an alias by adding the following to your ~/.profile or ~/.bashrc:

alias runlike="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock assaflavie/runlike"

Now runlike should be available as a local command:

runlike YOUR-CONTAINER

Install

$ pip install runlike

Status

This is very much a work in progress. Many docker run options aren't yet supported, but the most commonly used ones are. Feel free to send pull requests if you add any or if you happen to fix any (of the many) bugs this package undoubtedly has.

Probably shouldn't use this in production yet. If you do, double check that it's actually running what you want it to run.

Build Status

Supported Run Options

      --add-host list                  Add a custom host-to-IP mapping
                                       (host:ip)
      --cap-add list                   Add Linux capabilities
      --cap-drop list                  Drop Linux capabilities
                                       (0-3, 0,1)
      --cpuset-cpus string             CPUs in which to allow execution
                                       (0-3, 0,1)
      --cpuset-mems string             MEMs in which to allow execution
  -d, --detach                         Run container in background and
                                       print container ID
      --device list                    Add a host device to the container
      --dns list                       Set custom DNS servers
  -e, --env list                       Set environment variables
      --expose list                    Expose a port or a range of ports
  -h, --hostname string                Container host name
      --mac-address string             Container MAC address (e.g.,
                                       92:d0:c6:0a:29:33)
  -l, --label list                     Set meta data on a container
      --log-driver string              Logging driver for the container
      --log-opt list                   Log driver options
      --link list                      Add link to another container
  -m, --memory bytes                   Memory limit
      --memory-reservation bytes       Memory soft limit
      --name string                    Assign a name to the container
      --network string                 Connect a container to a network
                                       (default "default")
      --pid string                     PID namespace to use
      --privileged                     Give extended privileges to this
                                       container
  -p, --publish list                   Publish a container's port(s) to
                                       the host
      --restart string                 Restart policy to apply when a
                                       container exits (default "no")
      --rm                             Automatically remove the container
                                       when it exits
      --runtime string                 Runtime to use for this container
  -t, --tty                            Allocate a pseudo-TTY
  -u, --user string                    Username or UID (format:
                                       <name|uid>[:<group|gid>])
  -v, --volume list                    Bind mount a volume
      --volumes-from list              Mount volumes from the specified
                                       container(s)
  -w, --workdir string                 Working directory inside the container

Not Yet Supported Run Options (PRs are most welcome!)


  -a, --attach list                    Attach to STDIN, STDOUT or STDERR
      --blkio-weight uint16            Block IO (relative weight),
                                       between 10 and 1000, or 0 to
                                       disable (default 0)
      --blkio-weight-device list       Block IO weight (relative device
                                       weight) (default [])

      --cgroup-parent string           Optional parent cgroup for the
                                       container
      --cidfile string                 Write the container ID to the file
      --cpu-count int                  CPU count (Windows only)
      --cpu-percent int                CPU percent (Windows only)
      --cpu-period int                 Limit CPU CFS (Completely Fair
                                       Scheduler) period
      --cpu-quota int                  Limit CPU CFS (Completely Fair
                                       Scheduler) quota
      --cpu-rt-period int              Limit CPU real-time period in
                                       microseconds
      --cpu-rt-runtime int             Limit CPU real-time runtime in
                                       microseconds
  -c, --cpu-shares int                 CPU shares (relative weight)
      --cpus decimal                   Number of CPUs
      --detach-keys string             Override the key sequence for
                                       detaching a container
      --device-cgroup-rule list        Add a rule to the cgroup allowed
                                       devices list
      --device-read-bps list           Limit read rate (bytes per second)
                                       from a device (default [])
      --device-read-iops list          Limit read rate (IO per second)
                                       from a device (default [])
      --device-write-bps list          Limit write rate (bytes per
                                       second) to a device (default [])
      --device-write-iops list         Limit write rate (IO per second)
                                       to a device (default [])
      --disable-content-trust          Skip image verification (default true)
      --dns-option list                Set DNS options
      --dns-search list                Set custom DNS search domains
      --entrypoint string              Overwrite the default ENTRYPOINT
                                       of the image
      --env-file list                  Read in a file of environment variables
      --group-add list                 Add additional groups to join
      --health-cmd string              Command to run to check health
      --health-interval duration       Time between running the check
                                       (ms|s|m|h) (default 0s)
      --health-retries int             Consecutive failures needed to
                                       report unhealthy
      --health-start-period duration   Start period for the container to
                                       initialize before starting
                                       health-retries countdown
                                       (ms|s|m|h) (default 0s)
      --health-timeout duration        Maximum time to allow one check to
                                       run (ms|s|m|h) (default 0s)
      --help                           Print usage
      --init                           Run an init inside the container
                                       that forwards signals and reaps
                                       processes
  -i, --interactive                    Keep STDIN open even if not attached
      --io-maxbandwidth bytes          Maximum IO bandwidth limit for the
                                       system drive (Windows only)
      --io-maxiops uint                Maximum IOps limit for the system
                                       drive (Windows only)
      --ip string                      IPv4 address (e.g., 172.30.100.104)
      --ip6 string                     IPv6 address (e.g., 2001:db8::33)
      --ipc string                     IPC mode to use
      --isolation string               Container isolation technology
      --kernel-memory bytes            Kernel memory limit
      --label-file list                Read in a line delimited file of labels
      --link-local-ip list             Container IPv4/IPv6 link-local
                                       addresses

      --memory-swap bytes              Swap limit equal to memory plus
                                       swap: '-1' to enable unlimited swap
      --memory-swappiness int          Tune container memory swappiness
                                       (0 to 100) (default -1)
      --mount mount                    Attach a filesystem mount to the
                                       container

      --network-alias list             Add network-scoped alias for the
                                       container
      --no-healthcheck                 Disable any container-specified
                                       HEALTHCHECK
      --oom-kill-disable               Disable OOM Killer
      --oom-score-adj int              Tune host's OOM preferences (-1000
                                       to 1000)
      --pids-limit int                 Tune container pids limit (set -1
                                       for unlimited)
      --platform string                Set platform if server is
                                       multi-platform capable

  -P, --publish-all                    Publish all exposed ports to
                                       random ports
      --read-only                      Mount the container's root
                                       filesystem as read only

      --security-opt list              Security Options
      --shm-size bytes                 Size of /dev/shm
      --sig-proxy                      Proxy received signals to the
                                       process (default true)
      --stop-signal string             Signal to stop a container
                                       (default "SIGTERM")
      --stop-timeout int               Timeout (in seconds) to stop a
                                       container
      --storage-opt list               Storage driver options for the
                                       container
      --sysctl map                     Sysctl options (default map[])
      --tmpfs list                     Mount a tmpfs directory
      --ulimit ulimit                  Ulimit options (default [])

      --userns string                  User namespace to use
      --uts string                     UTS namespace to use
      --volume-driver string           Optional volume driver for the
                                       container

runlike's People

Contributors

abriko avatar albertosottile avatar anryko avatar gebhardtr avatar hugodelval avatar jonathanmorley avatar junka avatar kirktarou avatar lavie avatar mikedougherty avatar pfrenssen avatar rayjohnson avatar reconman avatar rubyfeinstein avatar sestegra avatar sh4wn avatar walle123 avatar zzzeek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

runlike's Issues

docker inspect misses quotation on the CMD

I believe Runlike is using solely inspect to find all values, though the container command lacks quotation that you will find if you do a docker ps --no-trunc, potentially causing the container to fail on launch.

does not catch --net host

hi,

Great tool. :)

The containers that we run it on have --net host and runlike does not seem to catch that. Output compared with the tool rekcod

bjolo

docker image doesn't catch up with the latest version

raw command version: (installed by pip2.7 install runlike)

# runlike 98f3e376f28c
docker run --name=eru_core_cachecloud-master-sg2-test-0.shopeemobile.com --hostname=cachecloud-master-sg2-test-0.shopeemobile.com --env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --volume=/etc/eru:/etc/eru --volume=/root:/root --network=host --restart=always --label ERU="1" --log-driver=journald --detach=true projecteru2/core /usr/bin/eru-core

docker image version: (pulled by docker pull assaflavie/runlike:latest)

# docker run --rm -v /var/run/docker.sock:/var/run/docker.sock assaflavie/runlike 98f3e376f28c
docker run --name=eru_core_cachecloud-master-sg2-test-0.shopeemobile.com --hostname=cachecloud-master-sg2-test-0.shopeemobile.com --env="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" --volume="/etc/eru:/etc/eru" --volume="/root:/root" --network=host --restart=always --label ERU="1" --detach=true projecteru2/core /usr/bin/eru-core

I'd like to highlight the difference that --log-driver is missed in docker image version.

Multiple published ports not detected

Example...
Container started with

docker run --name=nginx -v "nginx_conf:/etc/nginx" -p X.X.X.74:443:443 -p X.X.X.74:80:80 -p X.X.X.75:443:443 -p X.X.X.75:80:80 -d nginx:alpine

Runlike gives

$ runlike nginx
docker run --name=nginx --hostname=ff8f86b83bd0 --env="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" --env="NGINX_VERSION=1.17.10" --env="NJS_VERSION=0.3.9" --env="PKG_RELEASE=1" -p X.X.X.74:443:443 -p X.X.X.74:80:80 --label maintainer="NGINX Docker Maintainers <[email protected]>" --detach=true nginx:alpine nginx -g 'daemon off;'

It's missing the second ip address -p X.X.X.75:443:443 -p X.X.X.75:80:80

Custom DNS servers are not replicated

The option --dns allows you to specify a list of custom nameservers which will be written to the container's resolv.conf file. This is not replicated in the output of runlike, unfortunately.

Dockerise this?

Would it be possible to dockerise this application?

It sounds really useful, but I can't go around installing python & pip on our production boxes. But if it were available as a container I could pull that & run it inside docker.

I'm guessing it would need the docker socket to be mounted to give it access to the docker server? Or it could accept JSON piped from docker inspect via the cli and then output the reverse-engineered docker run command and exit.

$ docker inspect my_running_ctr | docker run assaflavie/runlike

Am I missing anything / are there other reasons that this wouldn't work?

docker-compose

Have you thought about generating a docker-compose file as well? While they typically combine a few services, a fragment would work well.

[Feature] add debug/entrypoint/interactive flag(s)

Pretty similar to runlike --no-name which when I run it now, I'd get:

docker run --hostname=... --detach=true -t <image>:latest

As runlike is used mainly for duplicating a container during debugging (well, at least in my case and per my assumption), then it would be great to have detach replaced with the following:

docker run --hostname=... --entrypoint bash -i -t <image>:latest

I saw there is a PR #58 has been sitting for more than year (and which is outdated already) but it'd be great to implement something like that based on that branch.

docker build caches previous pip versions

The Dockerfile does pip install runlike which gets cached locally, which can lead to old versions being tagged with new tags.
Either don't use pip at all when building the docker image, or pass the explicit version.

automate CI

  • Auto-publish to pypi on successful master build.
  • Auto push to dockerhub.
  • Autogen release notes and create github release draft.

Document supported docker run options

Many docker run options aren't yet supported, but the most commonly used ones are.

Can you document what specific docker run options are supported and which ones aren't? Great project btw! ๐Ÿ˜„

override inspected options with CLI options

e.g. if running with runlike -i ... then make the command output -i, even if inspected container runs in daemon mode
relevant for -i, -d, -t... and probably several other options.

Wrong docker links

Hi,
thanks for this very userful app.

There is an issue with links with runlike.

Runlike gives :
docker run --name=pydio --hostname=c7d2eaec413e --env="PGID=100" --env="PUID=1000" --env="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" --env="PS1=root@omv:/$ " --env="HOME=/root" --env="TERM=xterm" --env="PYDIO_VER=7.0.4" --volume="/storage_main/photo:/photo:ro" --volume="/etc/localtime:/etc/localtime:ro" --volume="/storage_main/pydio6/config:/config:rw" --volume="/storage_main/pydio6/data:/data:rw" --volume="/config" --volume="/data" --network=bridge -p 0.0.0.0:8004:443 --expose=80 --link /db:pydio --restart=no --label omv_docker_extra_args="--link db:mysql" --label build_version="Linuxserver.io version:- 51 Build-date:- April-07-2017-22:51:05-UTC" --detach=true linuxserver/pydio:51

in short :
--link /db:pydio

Docker inscpect gives :
"Links": [
"/db:/pydio/mysql"
],

as you can see the last "mysql" is cut.

doesn't work when docker run cmd args contain single quotes

docker inspect:

[
    {
        "Id": "*****",
        "Created": "2017-03-21T07:43:54.073781336Z",
        "Path": "/bin/sh",
        "Args": [
            "-c",
            "java   -Dnexus-work=${SONATYPE_WORK} -Dnexus-webapp-context-path=${CONTEXT_PATH}   -Xms${MIN_HEAP} -Xmx${MAX_HEAP}   -cp 'conf/:lib/*'   ${JAVA_OPTS}   org.sonatype.nexus.bootstrap.Launcher ${LAUNCHER_CONF}"
        ],
......

running runlike get:

docker run ***** /bin/sh -c 'java -Dnexus-work=${SONATYPE_WORK} -Dnexus-webapp-context-path=${CONTEXT_PATH} -Xms${MIN_HEAP} -Xmx${MAX_HEAP} -cp \'conf/:lib/*\' ${JAVA_OPTS} org.sonatype.nexus.bootstrap.Launcher ${LAUNCHER_CONF}'

but single quote cannot inside single quotes
https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Single-Quotes

use '"'"' instead of \' worked
https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings

Support Python3

Make a little change to make both Python2 and Python3 compatible

Misses labels assigned to containers

When running runlike on a container with labels, runlike doesn't include labels used when creating the container.

eg.

docker run -d -l traefik.port=9000 -l traefik.enable=true -v /var/run/docker.sock:/var/run/docker.sock -v /opt/portainer/data:/data --name=portainer portainer/portainer
% docker ps 
CONTAINER ID        IMAGE                                                   COMMAND                  CREATED             STATUS                  PORTS                                                              NAMES
5f8708530a52        portainer/portainer                                     "/portainer"             3 minutes ago       Up 3 minutes            9000/tcp                                                           portainer
% runlike 5f8708530a52
docker run --name=portainer --env="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" --volume="/var/run/docker.sock:/var/run/docker.sock" --volume="/opt/portainer/data:/data" --volume="/data" --expose=9000 --restart=no --detach=true portainer/portainer

support --ip6

runlike doesn't aware of --ip6.
I use below command to run a container, runlike -p doesn't ouput the --ip6 setting.

docker run -d --restart unless-stopped
--network mynetwork
--ip6 [ipv6 address]
--name test/test:v

Missing dependency on `wheel`

The setup requires wheel but this is not listed in the packages.

$ pip install runlike
Collecting runlike
  Using cached https://files.pythonhosted.org/packages/5e/e0/abbb08e276490a79492a25e130f9c3ff8ca331f715fdffa800093c467d27/runlike-0.6.0.tar.gz
Collecting Click (from runlike)
  Downloading https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl (81kB)
    100% |โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 81kB 921kB/s
Building wheels for collected packages: runlike
  Running setup.py bdist_wheel for runlike ... error
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-oHRXYW/runlike/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpX8a8RLpip-wheel- --python-tag cp27:
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help

  error: invalid command 'bdist_wheel'

  ----------------------------------------
  Failed building wheel for runlike
  Running setup.py clean for runlike
Failed to build runlike
Installing collected packages: Click, runlike
  Running setup.py install for runlike ... done
Successfully installed Click-7.0 runlike-0.6.0

What is also apparent is that the installation claims to be successful even though the build failed.

UnicodeDecodeError

I have a container running from the ownyourbits/nextcloudpi-armhf image. Trying to export with the command runlike nextcloud crashes with the following output:

Traceback (most recent call last):
  File "/usr/local/bin/runlike", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/runlike/runlike.py", line 28, in main
    cli()
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/runlike/runlike.py", line 23, in cli
    ins.inspect()
  File "/usr/local/lib/python2.7/dist-packages/runlike/inspector.py", line 32, in inspect
    self.facts = loads(output.decode())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 9939: ordinal not in range(128)

Avoid printing labels and environment variables inherited from the Docker image

Often Docker images have default labels and environment variables.

For example, if I run runlike against the pymedusa/medusa container, I get the following output:

docker run \
        --name=medusa \
        --hostname=medusa \
        --env=PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
        --env=LANG=C.UTF-8 \
        --env=GPG_KEY=A035C8C19219BA821ECEA86B64E628F8D684696D \
        --env=PYTHON_VERSION=3.10.4 \
        --env=PYTHON_PIP_VERSION=22.0.4 \
        --env=PYTHON_SETUPTOOLS_VERSION=58.1.0 \
        --env=PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/6ce3639da143c5d79b44f94b04080abf2531fd6e/public/get-pip.py \
        --env=PYTHON_GET_PIP_SHA256=ba3ab8267d91fd41c58dbce08f76db99f747f716d85ce1865813842bb035524d \
        --env=MEDUSA_COMMIT_BRANCH=develop \
        --env=MEDUSA_COMMIT_HASH=653207cbfc92323998acef7906bdc031326e57cc \
        --env=PUID=1034 \
        --env=PGID=65537 \
        --env=TZ=Europe/Vienna \
        --volume=/volume1/Data:/Data:rw \
        --volume=/volume1/docker/medusa:/config:rw \
        --volume=/Data \
        --volume=/anime \
        --volume=/config \
        --volume=/downloads \
        --volume=/tv \
        --network=portainer_default \
        --workdir=/app/medusa \
        -p 0.0.0.0:8081:8081 \
        --restart=always \
        --label='com.docker.compose.project=portainer' \
        --label='build_version=Branch: develop | Commit: 653207cbfc92323998acef7906bdc031326e57cc | Build-Date: 2022-10-20T13:46:23.787Z' \
        --label='org.opencontainers.image.source=https://github.com/pymedusa/Medusa' \
        --label='com.docker.compose.oneoff=False' \
        --label='org.opencontainers.image.description=Automatic Video Library Manager for TV Shows. It watches for new episodes of your favorite shows, and when they are posted it does its magic.' \
        --label='org.opencontainers.image.licenses=GPL-3.0' \
        --label='com.docker.compose.container-number=1' \
        --label='maintainer=pymedusa' \
        --label='com.docker.compose.service=medusa' \
        --label='com.docker.compose.version=2.5.1' \
        --label='org.opencontainers.image.version=develop' \
        --label='com.docker.compose.depends_on=' \
        --label='com.docker.compose.image=sha256:cabb96e5caea817a6536d125bbab09cf63ae225e19c96c2b3661d8efc480d718' \
        --label='com.docker.compose.project.config_files=/data/compose/2/docker-compose.yml' \
        --label='org.opencontainers.image.created=2022-10-20T13:46:23.787Z' \
        --label='org.opencontainers.image.title=Medusa' \
        --label='com.docker.compose.config-hash=fd086c0fa5957f7ef3d4047d01430849eaaeb0439ab52bc219c72e42ab051264' \
        --label='com.docker.compose.project.working_dir=/data/compose/2' \
        --label='org.opencontainers.image.revision=653207cbfc92323998acef7906bdc031326e57cc' \
        --label='org.opencontainers.image.url=https://github.com/pymedusa/Medusa' \
        --log-driver=db \
        -t \
        pymedusa/medusa:develop \
        runscripts/init.docker

All PYTHON_ environment variables and all labels are inherited from the original Docker image and lead to a giant reconstructed docker run command. Instead, the labels and environment variables from the image should not be printed at all.

This can be accomplished by cross-checking any container labels and env variables against the result of docker image inspect. If the container labels or env variables are part of the image definition with the exact same values, they don't need to be printed.

/etc/hosts file

if a local hosts file is used these are not propagated into the docker run file.
Would it be possible to include these as well like
--add-host webserver01:192.168.0.100

doesn't catch --privileged

runlike result doesn't include --privileged switch.

like
docker run -d --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.1.3

Feature Request: Support for podman

Would be nice to see this support podman. Most commands (if not all) are basically like aliases and work the same (e.g. podman inspect, etc)

Storing signatures
Error: statfs /var/run/docker.sock: no such file or directory
[root@fedora ~]# ls -lth /var/run/podman/podman.sock
srw-rw----. 1 root root 0 Apr 24 18:04 /var/run/podman/podman.so

ImportError: No module named 'inspector'

On my Debian 9 machine with Python 3.5 I get:

user@machine:~# 
Traceback (most recent call last):                                                                                                                                                                                                                                                                                   
  File "/usr/local/bin/runlike", line 7, in <module>                                                                                                                                                                                                                                                                 
    from runlike.runlike import main                                                                                                                                                                                                                                                                                 
  File "/usr/local/lib/python3.5/dist-packages/runlike/runlike.py", line 4, in <module>                                                                                                                                                                                                                              
    from inspector import Inspector                                                                                                                                                                                                                                                                                  
ImportError: No module named 'inspector' 

When I change the import statement in runlike.py to from .inspector import Inspector it works better. But then I get further errors. Is this Python 2 only?

Does not hande cases when command is empty

# runlike d57e739ff259
Traceback (most recent call last):
  File "/tmp/runlike/bin/runlike", line 9, in <module>
    load_entry_point('runlike==0.1.2', 'console_scripts', 'runlike')()
  File "/tmp/runlike/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/tmp/runlike/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/tmp/runlike/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/tmp/runlike/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/tmp/runlike/local/lib/python2.7/site-packages/runlike.py", line 126, in cli
    print ins.format_cli()
  File "/tmp/runlike/local/lib/python2.7/site-packages/runlike.py", line 111, in format_cli
    parameters = joiner.join(parameters)
TypeError: sequence item 25: expected string or Unicode, list found

After printing the parameters variable before
parameters = joiner.join(parameters)
it turns out that the last element of the list is also a list.
It seems like the issues is related to this code:

        command = []
        cmd = self.get_fact("Config.Cmd")
        if cmd:
            command = " ".join(cmd)
parameters.append(command)

If someone is using for example entrypoint and the command is empty the cmd string will be empty and a list is appended instead of a string, because the if is never evaluated.

Does not detect entrypoint

Great job on this project. It is very useful.
An issue I found is that the --entrypoint option is not detected. That information is in docker inspect so it should be an easy fix.

Crashes on JSON parsing

It does not seem to like the output from my inspect command ... Not sure if this is down to the old Docker version (19.03.6) running on the node I captured the output from?

$ cat out.txt | docker run --rm -v /var/run/docker.sock:/var/run/docker.sock assaflavie/runlike --stdin
Traceback (most recent call last):
  File "/usr/bin/runlike", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3.8/site-packages/runlike/runlike.py", line 37, in main
    cli()
  File "/usr/lib/python3.8/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.8/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/runlike/runlike.py", line 31, in cli
    ins.set_facts(raw_json)
  File "/usr/lib/python3.8/site-packages/runlike/inspector.py", line 40, in set_facts
    self.facts = loads(raw_json)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

out.txt

error: runlike -p container_name

ubuntu@VM-0-12-ubuntu:~$ runlike -p postgres
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.8/site-packages/runlike/inspector.py", line 29, in inspect
output = check_output(
File "/usr/lib/python3.8/subprocess.py", line 411, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.8/subprocess.py", line 512, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['docker', 'inspect', 'postgres']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/ubuntu/.local/bin/runlike", line 8, in
sys.exit(main())
File "/home/ubuntu/.local/lib/python3.8/site-packages/runlike/runlike.py", line 28, in main
cli()
File "/usr/lib/python3/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/lib/python3/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/lib/python3/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/ubuntu/.local/lib/python3.8/site-packages/runlike/runlike.py", line 23, in cli
ins.inspect()
File "/home/ubuntu/.local/lib/python3.8/site-packages/runlike/inspector.py", line 34, in inspect
if "No such image or container" in e.output:
TypeError: a bytes-like object is required, not 'str'

Special characters in arguments interfere with command

Let's say I generated the command for running portainer:

docker run \
    --detach=true \
    --label traefik.frontend.rule="Host:my.host.com" \
#           ^-------- 1 --------^ ^------- 2 ------^
    portainer/portainer \
    --admin-password \
    $2y$17$P06LST8KwocXXXXXXX
#   ^---------- 3 ----------^
  1. I noticed that labels and environment variables have their values quoted instead of the whole argument. I'm not sure if this is the best behaviour (what if the label key contains special characters or a space?).
  2. Since double quotes are generally used, I also wondered if they could be susceptible to variable expansion, so maybe single quotes should be used instead. This might apply to other places too.
  3. Since arguments are not escaped, if they contain special characters they interfere with the generated command.

travis-ci stopped working

Currently CI is borked. A few issues:

  1. dockerhub is throttling image pulls, so the build fails quite early.
  2. travis-ci.org itself seems to be "shutting down"? when I log in they urge me to "upgrade" to travis-ci.com so I need to see if there's some other free option.

Meanwhile, no releases, and possibly no more docker image released if it means paying dockerhub.

Broken pypi package

Hello,

I am packaging runlike to AUR

When I am trying to upgrade runlike from 0.7.0 to 1.0.0, I think the pypi package is broken.

The setup.py file is missing entry_points block which results in no /usr/bin/runlike is created.

I try to install runlike via pip, also failed.

docker run -it --rm python:3.9 /bin/bash
pip install runlike

# runlike
bash: runlike: command not found

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.