Xubuntu [SOLVED]: apt-get commands doesn't work in docker containers

Xubuntu [SOLVED]: apt-get commands doesn't work in docker containers

Home Forums Xubuntu Xubuntu [SOLVED]: apt-get commands doesn't work in docker containers

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36869

    Anonymous

    QuestionQuestion

    I’m trying to install some packages in a docker image, but apt-get commands seems not to work…

    When I try this in a container based on ubuntu:16.04

    apt-get update && apt-get install -y openssh-server
    

    I got this:

    Err:1 http://archive.ubuntu.com/ubuntu zesty InRelease
      Temporary failure resolving 'archive.ubuntu.com'
    Err:2 http://security.ubuntu.com/ubuntu zesty-security InRelease
      Temporary failure resolving 'security.ubuntu.com'
    Err:3 http://archive.ubuntu.com/ubuntu zesty-updates InRelease
      Temporary failure resolving 'archive.ubuntu.com'
    Err:4 http://archive.ubuntu.com/ubuntu zesty-backports InRelease
      Temporary failure resolving 'archive.ubuntu.com'
    Reading package lists... Done
    W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/zesty/InRelease  Temporary failure resolving 'archive.ubuntu.com'
    W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/zesty-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
    W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/zesty-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com'
    W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/zesty-security/InRelease  Temporary failure resolving 'security.ubuntu.com'
    W: Some index files failed to download. They have been ignored, or old ones used instead.
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: Unable to locate package openssh-server
    

    I tried to do this in a Dockerfile like this

    FROM ubuntu:16.04
    RUN apt-get update && apt-get -y install openssh-server
    CMD bin/bash
    

    and build this with

    sudo docker build -t imagetest .
    

    but I got this:

    Sending build context to Docker daemon  2.048kB
    Step 1/3 : FROM ubuntu:16.04
     ---> 00fd29ccc6f1
    Step 2/3 : RUN apt-get update && apt-get install openssh-server
     ---> Running in ee011c1239d0
    Err:1 http://archive.ubuntu.com/ubuntu xenial InRelease
      Temporary failure resolving 'archive.ubuntu.com'
    Err:2 http://security.ubuntu.com/ubuntu xenial-security InRelease
      Temporary failure resolving 'security.ubuntu.com'
    Err:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
      Temporary failure resolving 'archive.ubuntu.com'
    Err:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease
      Temporary failure resolving 'archive.ubuntu.com'
    Reading package lists...
    W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease  Temporary failure resolving 'archive.ubuntu.com'
    W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
    W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com'
    W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease  Temporary failure resolving 'security.ubuntu.com'
    W: Some index files failed to download. They have been ignored, or old ones used instead.
    Reading package lists...
    Building dependency tree...
    Reading state information...
    E: Unable to locate package openssh-server
    The command '/bin/sh -c apt-get update && apt-get install openssh-server' returned a non-zero code: 100
    

    I searched on the official doc and some forums but none of the answers I found help me and are old…

    Some of them said to restart the docker service, but it doesn’t work for me..
    Some others said to use apt-get update -qq, but it doesn’t work too…

    So I came here to ask directly and have a recent answer.

    Thanks.

    #36870

    Anonymous

    Accepted AnswerAnswer

    If apt-get is working fine on the VM, you can build the container using network host mode.

    docker build --network=host ...
    

    Source: https://stackoverflow.com/questions/48023238/apt-get-commands-doesnt-work-in-docker-containers
    Author: yamenk
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.