No Docker config.json in Amazon Linux EC2

Issue

So in order to set up the amazon-ecr-credential-helper I need to add some lines to the .docker/config.json file in my EC2. When I try to run the script

  echo "{ \"credHelpers\": { \"acc_id.dkr.ecr.acc_region.amazonaws.com\": \"ecr-login\" } }" > ~/.docker/config.json

I get an error -bash: /root/.docker/config.json: No such file or directory

enter image description here

Docker is installed, I’m using root user. This is an Amazon Linux EC2. Can someone please tell me what is wrong here? Doesn’t Docker already create the .docker folder? Or is this something I need to do?

Some context: I intend to run this script as part of the EC2 Userdata, but have been facing issues, so trying to debug within the container first.

Any hints in the right direction would be highly appreciated.
Thanks!

Solution

"Doesn’t Docker already create the .docker folder?"

No, Docker doesn’t create a .docker folder in every user’s home directory. You need to create that folder yourself.

Answered By – Mark B

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published