Attach and run a command in a docker container

I have a docker container running /bin/bash

So I can attach to it and run commands like

  • git ssh can't access to gitlab in a docker container
  • How about the docker run in virtul machine best practice?
  • Docker security issue
  • OSI Layer Model for Docker?
  • docker installed with brew fails on /var/run/docker.sock
  • Access KVM VM over the network from a Docker container
  • docker attach <container id>
    bash# apt-get install package

    Is there a way I can do this in a single docker command instead, maybe something like this:

    docker attach <container id> "apt-get install package"

  • Kubernetes v1.2.2 api-server dosen't start
  • How to list all tags for a Docker image on a remote registry?
  • Docker Packages: Hash Sum Mismatch
  • What are <none> repository and tags? Why do they appear when I use docker build?
  • Elastic Beanstalk Django Deployment With Preconfigured Docker Container
  • Adding SSL certificates to Website to Docker
  • One Solution collect form web for “Attach and run a command in a docker container”

    This should work.

    echo 'sudo apt-get install package' | docker attach <container id>

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.