Docker Community Forums

Share and learn in the Docker community.

Using program in a Docker container


(Jgossage) #1

I am using Docker for Windows Community Edge edition. I am a newbie and I am trying to follow the Getting Started tutorial for Docker for Windows. I have installed it on Wndows 10 without apparent problems. One of the commands in the tutorial is

docker run -it ubuntu bash

which should start a Ubuntu instance running the bash shell. How do I interact with this copy of bash? I have been completely unable to find a way. Also I have been unable to find any documentation on the -it option to run.

(Mario Pietsch) #2

If you open a powershell and type docker version
What do you get?

(Jgossage) #3

The version is 17.09.0-ce-rc3.

My problem, at this point is conceptual. In a normal machine, you can access bash from a graphical terminal program such as Gnome-terminal, or from one of the low-level Linux consoles. Either way gives you an environment that allows you to interact directly with bash. My problem is to understand how to invoke bash in a container under Docker so that I can interact with it as if I was on a bare non-Docker machine.

(David Maze) #4

It’s exactly what you said initially:

docker run --rm -it ubuntu:16.04 bash

Note that the Docker environment is very different from a full-blown Linux VM. If you’re looking for a graphical terminal to “interact with the machine”, a VM-based solution might be a better match. (It is difficult at best to run a graphical application from Docker.)

The thing Docker is really good at is packaging and running single-task network processes, especially things like Web-based microservices. Read up on the Dockerfile system. Plan to routinely delete your containers. It’s rare IME to use an interactive shell to work with a container unless I’m trying to debug it.

(Mario Pietsch) #5

Works for me.

PS C:\Users\test> docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
9fb6c798fa41: Pull complete
3b61febd4aef: Pull complete
9d99b9777eb0: Pull complete
d010c8cf75d7: Pull complete
7fac07fb303e: Pull complete
Digest: sha256:31371c117d65387be2640e23d2abe1f6f4667e47716483f1
Status: Downloaded newer image for ubuntu:latest
root@536d3f9:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

For me docker version prints:

PS C:\Users\test> docker version
 Version:      17.06.2-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   cec0b72
 Built:        Tue Sep  5 19:57:19 2017
 OS/Arch:      windows/amd64

 Version:      17.06.2-ce
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   cec0b72
 Built:        Tue Sep  5 19:59:19 2017
 OS/Arch:      linux/amd64
 Experimental: true

(Jgossage) #6

When I tried to run bash as you show, the run command never returned after 1 hr. waiting and I had to do Ctrl-C to get a prompt. The bash prompt was never displayed.

(Michael Friis) #7

What shell are you using? Powershell ISE probably won’t work.

(Smartersec) #8

Have you tried setting it up as a reverse shell using netcat?

(Gossem) #9

This was the solution for me. Regular Windows PowerShell worked right away.

docker run -it ubuntu bash