Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Docker – Lecture 7 part 2

Docker Basic Commands:

❑ Go through Docker command basics


❑ Go through Dockerhub basics
❑ Go through Repositories basics
Docker – Basic Commands
Go through Docker command basics

▪ Docker commands documentation: https://docs.docker.com/engine/reference/commandline/docker/

▪ The -d parameter instructs docker use detached mode, i.e. in the background and also prints the container
ID. The below examples are the same command.
docker run -d -p 8080:8080 exercises:0.6
docker run --detached --publish 8080:8080 exercises:0.6
Source: --detach (-d) at https://docs.docker.com/engine/reference/commandline/run/

▪ To logon to an image use the interactive parameter --interactive (-i) with the run command. Also use the
--tty (-t) parameter which allocates a pseudo terminal. The command will start a container and an
interactive bash shell specified by /bin/bash, on some images and system this may be the default
command.
docker run -it eclipse-temurin:17.0.6_10-jdk /bin/bash
docker run --interactive --tty eclipse-temurin:17.0.6_10-jdk /bin/bash
Source: --interactive (-i) and --tty (-t) at https://docs.docker.com/engine/reference/commandline/run/
Docker – Basic Commands
Go through Docker command basics

▪ Docker commands documentation: https://docs.docker.com/engine/reference/commandline/docker/

▪ To execute a command on a running container use exec together with the interactive terminal mode. The
command will run an interactive bash shell on the running container. Use the /bin/bash command if this is
not the default on the image or system.
docker exec -it <container_name or id> /bin/bash
Source: https://docs.docker.com/engine/reference/commandline/exec/
▪ To list all docker images on windows and filter with several words
docker image ls | findstr "TAG eclipse“
Source: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/findstr

▪ To list docker logs for a container


docker logs <container name or id>
docker logs jolly_faraday
Docker – Basic Commands
Go through Docker command basics

▪ Docker commands documentation: https://docs.docker.com/engine/reference/commandline/docker/

▪ When you have started running an interactive bash against a running container you can execute commands.
Base images usually don’t have much software installed so you need to install programs you want to use.
For example, on a Linux image you can update apt and install net-tools.
apt update
apt install net-tools

▪ Then you will be able to run for example netstat and se what application are listening on what ports.

You might also like