In the Docker development environment, it is necessary to operate with commands specific to the Docker development environment, but we will introduce a method that allows you to develop with the same commands as when executing commands in the script language in the local environment.
Docker 19.03.8 Ruby 2.5 Rails 5.2
For example, the following commands used in the development of Ruby on Rails
$ rails db:migrate
When executing this command with Docker
$ docker-compose run web rails db:migrate
The command looks like this. There are other operation methods, but if you develop with Ruby on Rails, normal commands of Ruby and Rails are easier. In that case, execute the command according to the following procedure.
Launch Docker.
$ docker-compose start
Look up the container name.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a9b19e00552e recipegram_web "entrypoint.sh bash …" 44 hours ago Up 11 seconds 0.0.0.0:3000->3000/tcp recipegram_web_1
975875c12c76 postgres "docker-entrypoint.s…" 46 hours ago Up 12 seconds 5432/tcp recipegram_db_1
Enter the container name and execute the following command.
$ docker exec -it a9b19e00552e bash
Then it will switch like this, so in this state you can develop with Ruby or Rails execution command ^ _ ^
root@a9b19e00552e:/myapp#