A solution to Docker errors that beginners tend to get stuck in

Article background

After graduating from Le Wagon Tokyo (https://www.lewagon.com/ja/tokyo), an English programming school from France that mainly teaches Ruby and Rails, I started studying Docker. I built Docker on a project I worked on after graduation, but I faced many errors. I solved the error by self-education through trial and error, so it took a lot of time. I think there are many people like me who have had trouble with errors when they first touch Docker, so I decided to write this article, hoping that the solution I used would be helpful.

1 PermissionError (Permission denied :‘~~~/your_app/tmp/db’) As far as I can see from the official Docker documentation, this error seems to be for Linux users only, but I'll share Permission as it can be annoying for Linux users. This error occurs because Docker creates a temporary database (db folder), but the currently logged in Linux user does not have the right to use that database.

First, use this command to move to that temporary folder.

$ cd ~~~(Path to your app)/(Your own app name)/tmp

Check which users can use the db folder with the following command.

$ ls -la

If you don't see the name of the currently logged-in Linux user, give that user permission with the following command:

$ sudo chown -R (Linux user name) . 
password for (Linux user name):

Since it is a sudo command, you will be prompted to enter the password. At this point, you should be able to run major Docker commands such as "docker-compose build" and "docker-compose up" without any problems.

note: With a similar error, I said "FATAL: could not open file" I often see the error "global / pg_filenode.map": Permission denied ", but this is okay if you restart with" docker-compose stop "→" docker-compose up ".

2 No space left on your device This error occurs when the capacity of the Docker image becomes large due to the setting of Dockerfile. Unnecessary images and containers can be easily deleted with the following command.

$ docker image prune
$ docker container prune

When you enter these commands, you will see the following message:

WARNING! This will remove all dangling images (Or containers).
Are you sure you want to continue? [y/N]

Enter "y" because dangling images means unnecessary images. You should have enough space to run the same major Docker commands as when resolving a PermissionError.

If you need to remove more, look for the image you want to remove below.

$ docker images

After confirming the ID of the image you want to erase, delete it below.

$ docker image rm -f (ID of the image you want to erase)

References

Although in English, this book is recommended as it discusses in great detail how to use Docker in Ruby on Rails projects.

Docker for Rails Developers: https://pragprog.com/titles/ridocker/

Unfortunately, there are few Docker materials for Rails including English, so if you have a short history of Rails and want to read easy materials about Docker, it is English, but it is worth reading. think.

Medium English Articles

I wrote an article in English on Medium in more detail on this subject, so please take a look there as well.

https://medium.com/@shogohida_81081/5-solutions-to-common-errors-of-docker-for-beginners-c04dc1237c78

Recommended Posts

A solution to Docker errors that beginners tend to get stuck in
Get stuck in a Java primer
Commands that helped resolve errors in Docker
A story that got stuck with an error during migration in docker PHP laravel
Spring boot Things that beginners tend to have (@ComponentScan)
With podman in docker, everyone wants to get along and use docker on a shared computer
How to implement a job that uses Java API in JobScheduler
I'm stuck trying to get my own annotations working in Eclipse
How to get JDK 11 on your mac in a comfortable way
How to get parameters in Spark
A shell script that builds a Docker image and pushes it to ECR
How to get the current date as a string in yyyyMMdd format
How to get the absolute path of a directory running in Java
[Java] [For beginners] How to insert elements directly in a 2D array
[Ruby / Rails] Use alias. In a way that rubocop won't get angry!