Compose: docker-compose exec doesn't have -e option?

Created on 1 Mar 2017  路  5Comments  路  Source: docker/compose

docker-compose run:

Run a one-off command on a service.

For example:

    $ docker-compose run web python manage.py shell

By default, linked services will be started, unless they are already
running. If you do not want to start linked services, use
`docker-compose run --no-deps SERVICE COMMAND [ARGS...]`.

Usage: run [options] [-p PORT...] [-e KEY=VAL...] SERVICE [COMMAND] [ARGS...]

Options:
    -d                    Detached mode: Run container in the background, print
                          new container name.
    --name NAME           Assign a name to the container
    --entrypoint CMD      Override the entrypoint of the image.
    -e KEY=VAL            Set an environment variable (can be used multiple times)
    -u, --user=""         Run as specified username or uid
    --no-deps             Don't start linked services.
    --rm                  Remove container after run. Ignored in detached mode.
    -p, --publish=[]      Publish a container's port(s) to the host
    --service-ports       Run command with the service's ports enabled and mapped
                          to the host.
    -T                    Disable pseudo-tty allocation. By default `docker-compose run`
                          allocates a TTY.
    -w, --workdir=""      Working directory inside the container

docker-compose exec:

Execute a command in a running container

Usage: exec [options] SERVICE COMMAND [ARGS...]

Options:
    -d                Detached mode: Run command in the background.
    --privileged      Give extended privileges to the process.
    --user USER       Run the command as this user.
    -T                Disable pseudo-tty allocation. By default `docker-compose exec`
                      allocates a TTY.
    --index=index     index of the container if there are multiple
                      instances of a service [default: 1]

Why doesn't exec support environment command? Documentation for docker-compose exec reads "This is equivalent of docker exec." And documentation for docker exec DOES list --env parameter.

exbeginner kinfeature kinparity

Most helpful comment

I am using this for now:

docker-compose exec <service> env VAR=VAL bash -l

All 5 comments

@shin- I would take this PR. Could you guide me a little

@shin- ping

I am using this for now:

docker-compose exec <service> env VAR=VAL bash -l

https://github.com/moby/moby/issues/14036#issuecomment-287560131

this was implemented docker exec now has an --env option; https://docs.docker.com/engine/reference/commandline/exec/#usage

https://github.com/moby/moby/pull/24594

$ docker exec --help

Usage:  docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

Run a command in a running container

Options:
  -d, --detach               Detached mode: run command in the background
      --detach-keys string   Override the key sequence for detaching a container
  -e, --env list             Set environment variables
      --help                 Print usage
  -i, --interactive          Keep STDIN open even if not attached
      --privileged           Give extended privileges to the command
  -t, --tty                  Allocate a pseudo-TTY
  -u, --user string          Username or UID (format: <name|uid>[:<group|gid>])

compose has it still missing

$ docker-compose exec --help
Execute a command in a running container

Usage: exec [options] SERVICE COMMAND [ARGS...]

Options:
    -d                Detached mode: Run command in the background.
    --privileged      Give extended privileges to the process.
    -u, --user USER   Run the command as this user.
    -T                Disable pseudo-tty allocation. By default `docker-compose exec`
                      allocates a TTY.
    --index=index     index of the container if there are multiple
                      instances of a service [default: 1]

+1 The env workaround is a bit messy to remember.

Was this page helpful?
0 / 5 - 0 ratings