Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting a shell in the Docker Alpine container

To start an interactive shell for the Ubuntu image we can run:

ole@T:~$ docker run -it --rm ubuntu
root@1a6721e1fb64:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

But when this is run for the Alpine Docker image, the following results:

ole@T:~$ docker run -it --rm alpine
Error response from daemon: No command specified

What is the command for starting an interactive shell in an Alpine base container?

like image 564
Ole Avatar asked Oct 16 '22 13:10

Ole


People also ask

Does alpine have a shell?

3. Starting a Shell in an Alpine Container. Alpine is the most lightweight Linux distribution. Due to its small size, many people are using Alpine as their base image.


2 Answers

ole@T:~$ docker run -it --rm alpine /bin/ash
(inside container) / # 

Options used above:

  • /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
like image 407
Ole Avatar answered Oct 18 '22 03:10

Ole


Usually, an Alpine Linux image doesn't contain bash, Instead you can use /bin/ash, /bin/sh, ash or only sh.

/bin/ash

docker run -it --rm alpine /bin/ash

/bin/sh

docker run -it --rm alpine /bin/sh

ash

docker run -it --rm alpine ash

sh

docker run -it --rm alpine sh

I hope this information helps you.

like image 94
jansanchez Avatar answered Oct 18 '22 03:10

jansanchez