Basic examples

Run ubuntu with interactive shell (bash by default)

$ docker container run -it --name ubuntu ubuntu
  • -i - interactive
  • -t - tty

When we exit bash, the container will exit as well.

  • Run an existing container with an interactive shell
$ docker container start -ai ubuntu    # bash is default so we don't need to specify it
  • -a - attach

  • -i - interactive

Manage running MYSQL server

  • I have mysql running in the background (dettached)
~> docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
875756c3adc3        mysql               "docker-entrypoint..."   About an hour ago   Up About an hour    3306/tcp            mysql

~> docker container exec -it mysql bash
root@875756c3adc3:/~> ps aux | grep mysqld
mysql         1  0.0  4.9 1204900 201128 ?      Ssl  07:08   0:01 mysqld

Alpine Linux

  • There is no bash (ughhh, what?)
~> docker container run -it alpine bash
docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "exec: \"bash\": executable file not found in $PATH".
  • But there is SH so you can connect into it
docker container run -it alpine sh
root:~>

Format and some outputs

  • I have running default detached, published nginx under the name webhost
~> docker container port webhost
80/tcp -> 0.0.0.0:80

~> docker container inspect --format '{{ .NetworkSettings.IPAddress }}' webhost
172.17.0.4

results matching ""

    No results matching ""