Search code examples
linuxdockerdebian

E: Malformed entry 1 in list file /etc/apt/sources.list.d/docker.list (Component)


I started a new class and I am new in using Linux. I use debian and I follow to teacher guide to install git and docker. I entered all the commands in the terminal until I had some error.

  1. sudo apt install git worked

git config --global user.name "Ion Popescu"
git config --global user.email "ion.popescu@gmail.com"
git config --global core.editor vim
git config --global core.pager more
git config --global help.autocorrect true 

all worked

  1. sudo apt-get -y remove docker docker-engine docker.io worked

sudo apt update
sudo apt install -y apt-transport-https ca-certificates wget
sudo apt install -y software-properties-common ssh

worked all of them

5.

wget https://download.docker.com/linux/debian/gpg
sudo apt-key add gpg

worked

  1. echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee -a /etc/apt/sources.list.d/docker.list worked

Now I have to enter these lines but I get an error after the first one

7.

sudo apt update
sudo apt-cache policy docker-ce
sudo apt -y install docker-ce

E: Malformed entry 1 in list file /etc/apt/sources.list.d/docker.list (Component) E: The list of sources could not be read.

How to solve this?


Solution

  • To make sure that /etc/apt/sources.list.d/docker.list is formatted correctly use the following command (tee without -a to override the source):

    On debian Buster:

    printf "%s\n" "deb [arch=amd64] https://download.docker.com/linux/debian buster stable" |\
    sudo tee /etc/apt/sources.list.d/docker.list
    

    On debian Stretch:

    printf "%s\n" "deb [arch=amd64] https://download.docker.com/linux/debian stretch stable" |\
    sudo tee /etc/apt/sources.list.d/docker.list
    

    (You can use $(lsb_release -cs) instead of debian codename which require lsb-release package to be installed.)

    An alternative way to add docker-ce repository: You have already installed software-properties-common, you can use add-apt-repository to add the repository:

    sudo add-apt-repository \
       "deb [arch=amd64] https://download.docker.com/linux/debian \
       $(lsb_release -cs) \
       stable"
    

    Docker-ce docs