Docker refuses to execute commands or start containers with Ubuntu 20 image on Ubuntu 21 host, but works on Ubuntu 20 host



  • So I've pulled the amd64/ubuntu:latest image, which is an Ubuntu 20 image for docker and customized it a bit. Not much - zsh, vim, locales and openssh-server compiled from source (because the package wants me to download 100Mb of some stuff, whereas the compiled version is only 1.5 Mb)

    In this case, I don't think those are the reason for the following problem: I did not intend to use Dockerfiles with this one, and I created and ran containers with the following command:

    $ docker run -dit --network=my_docker_network --name=MyContainer \
      local/ubuntu:latest
    

    This works fine on my Ubuntu 20.04 - notice how there isn't a command after the image name, which, as per documentation, is supposed to be there, but it looks like it isn't needed here. The sshd is later started manually by the docker exec command and works fine.

    Now, to test the compatibility, I've installed Ubuntu 21 on a VirtualBox, then installed docker there and imported my custom image local/ubuntu:latest. Docker versions and the way they are run seem to be exactly the same - v20.10.12. When I run the same docker run... command on Ubuntu 21, it refuses to start start the image, saying another argument - the COMMAND - is require. Yet when I provide ANY command as the last argument, for example:

    $ docker run -dit --network=my_docker_network --name=MyContainer \
      local/ubuntu:latest /usr/bin/sh -c 'echo OK'
    

    or

    $ docker run -dit --network=my_docker_network --name=MyContainer \
      local/ubuntu:latest /usr/bin/sshd
    

    it says they're not in $PATH or file doesn't exist.

    If I try and create a container first, it is indeed created with:

    $ docker create -it --network=my_docker_network --name=MyContainer \
      local/ubuntu:latest
    

    But the same problem occurs once I try actually starting it. What is this? What am I missing?



  • Asked on the Docker forums - apparently to correctly "import" the image, you don't user the import command but instead user image load command.

    INCORRECT:

    $ docker image save local/ubuntu:latest -o ubuntu.tgz # on Ubuntu 20
    $ docker import ubuntu.tgz local/ubuntu:latest        # WRONG! on Ubuntu 21
    

    CORRECT:

    $ docker image save local/ubuntu:latest -o ubuntu.tgz # on Ubuntu 20
    $ docker image load -i ubuntu.tgz                     # on Ubuntu 21
    

    Credits go to the person who https://forums.docker.com/t/same-image-refuses-to-run-on-ubuntu-21-but-runs-on-ubuntu-20-docker-versions-are-the-same/121955 on the Docker forum here. Also note, that if you run docker image save the image full name (repo/name:tag) is actually save with along with other information, so upon running docker image load -i ubuntu.tgz Docker will tag that image as exactly as it was tagged when it was saved. If an image with the same name exists, it will be replaced, so be careful.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2