25
loading...
This website collects cookies to deliver better user experience
$ docker run --publish 127.0.0.1:8080:10000/tcp helloFromIntegratnIO
docker run
: Here we are telling the Docker cli that we want to run an image as a container.-publish
: Publish will bind a local port to a port in the container.127.0.0.1
: Keeps us only exposing localhost, so our container won't be available outside of our machine.:8080
: is the local port on our host machine that we are binding to:10000
: is the port inside the container that we want 8080
to impersonate./tcp
: is the protocol we want to use. You could also use udp
or sctp
if needed. You can learn more about that in the User Guide$ docker run -p 127.0.0.1:8080:10000/tcp helloFromIntegratnIO
Starting Web Server
Preparing to handle requests
Ready for requests
$ curl localhost:8080
$ curl localhost:8080
Hello from Integratn.IO!!!
MESSAGE
to equal something else. Rebuild our image. Then finally run it again. This is a great method for establishing default values for environment variables. Or we can add the parameter --env with a value to our docker run
command and change it on the fly. Environment Variables passed during a docker run
command will always trump what is in your Dockerfile. If you haven't exited the container already hit ctrl +c
to exit the container from the terminal.docker run --env MESSAGE="Hello from outerspace" -p 127.0.0.1:8080:10000/tcp helloFromIntegratnIO
$ curl localhost:8080
Hello from outerspace
$ docker ps
NAMES
field will not be the same.$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
56290825f889 helloFromIntegratnIO "/go/bin/hello" 2 minutes ago Up 2 minutes 127.0.0.1:8080->10000/tcp hungry_bohr
docker exec --interactive --tty hungry_bohr /bin/sh
$ docker exec --interactive --tty hungry_bohr /bin/sh
/go/src/integratnio/go-rest-api #
WORKDIR
in the Dockerfile. We are in the shell of the container. Type exit
and hit enter
to leave the container.docker exec
is the base command. This is declaring that we want to execute something against a running container.--interactive
will keep STDIN open even if we aren't attached.--tty
gives us a pseudo tty.hungry_bohr
is the name of my running container. Yours will be different./bin/sh
This is the command we want to run in the container. One caveat to this. Whatever you run against the container has to actually be part of the container. In an effort to trim containers down a lot of container images don't have a shell command available.