Docker Alpine
2021-11-19 本文已影响0人
JaedenKil
- Pull Alpine
docker pull alpine
- Run Alpine commands
$ docker run -it --rm alpine /bin/ash
/ # whoami
root
/ #
-
/bin/ash
is Ash (Almquist Shell) provided by BusyBox -
--rm
Automatically remove the container when it exits (docker run --help
) -
-i
Interactive mode (Keep STDIN open even if not attached) -
-t
Allocate a pseudo-TTY
- Start a docker image with a name in interactive shell mode
docker run --name MH -it alpine /bin/ash
/ # whoami
root
/ # mkdir TestDir
- Check containers
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
385f6532da25 alpine "/bin/ash" 3 minutes ago Up 2 minutes MH
- Run the container
$ docker exec -it MH /bin/ash
/ # ls -al TestDir/
total 8
drwxr-xr-x 2 root root 4096 Nov 19 08:32 .
drwxr-xr-x 1 root root 4096 Nov 19 08:32 ..
Reference: https://docs.docker.com/engine/reference/commandline/exec/
Reference: https://docker-curriculum.com/
Commands:
- Check docker images:
docker images
- Run commands
$ docker run alpine echo "Hello Alpine"
Hello Alpine
- Check running containers
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
53eae49a4afa alpine "echo 'Hello Alpine'" 52 seconds ago Exited (0) 51 seconds ago stoic_bohr
93e88e70e838 ubuntu:latest "bash" 2 months ago Exited (255) 12 minutes ago admiring_wright
909907b45f5a ubuntu "bash" 2 months ago Exited (0) 2 months ago serene_joliot
0b4e542857be ubuntu "bash" 2 months ago Exited (0) 2 months ago amazing_knuth
- Remove containers
$ docker rm 93e88e70e838 909907b45f5a 0b4e542857be
93e88e70e838
909907b45f5a
0b4e542857be