dockerfile
FROM ruby:2.5.1
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN mkdir /myapp
ENV APP_ROOT /myapp
WORKDIR $APP_ROOT
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]
entrypoint.sh Directly under the project directory
entrypoint.sh
#!/bin/bash
set -e
rm -f /myapp/tmp/pids/server.pid
exec "$@"
docker-compose-yml
docker-compose.yml
version: '3'
services:
web:
build:
context: .
dockerfile: Dockerfile
command: bundle exec rails s -p 3000 -b '0.0.0.0'
tty: true
stdin_open: true
depends_on:
- db
ports:
- "3000:3000"
volumes:
- .:/myapp:delegated
db:
image: mysql:5.7
environment:
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: password
ports:
- '3316:3306'
volumes:
- ./db/mysql/volumes:/var/lib/mysql
#Container list(Including those that are stopped)
$ docker ps -a
#Container ID list
$ docker ps -a -q
#Delete container
$ docker rm [Container ID]
#(Forced) container deletion
$ docker rm -f [Container ID]
#Go inside the container
$ docker-compose exec web bash
#(1) Exit the container
$ exit
# (2)Get out of the container
Ctrl + P + Q (Without stopping the container)
docker-compose build Build only the image, not the container. Of course, it doesn't even start the container
docker-compose up If there is an image cache, build and start the container from there. If there is no image cache, build the image with build and build / start the container.
docker-compose start
Launch any already built containers, if any (Stop the container with docker-compose stop)
docker-compose run Execute the command in the container of the service specified by the argument
$ docker-compose run web rails s
$ docker-compose run web rails c
etc,,,,
https://qiita.com/tegnike/items/bcdcee0320e11a928d46 [Reverse lookup of docker-compose command for beginners](https://qiita.com/okyk/items/a374ddb3f853d1688820 #) [Docker-compose command summary](https://qiita.com/wasanx25/items/d47caf37b79e855af95f#%E5%8F%82%E8%80%83%E3%83%AA%E3%83%B3%E3%82 % AF #)
[Mac docker will be free from slow stress](https://qiita.com/ysKey2/items/346c429ac8dfa0aed892 #)
docker-compose.yml
#Example
services:
app:
volumes:
- .:/project/sample_app:delegated
Autoprefixer doesn’t support Node v4.8.2.
web_1 | ActionView::Template::Error (Autoprefixer doesn’t support Node v4.8.2. Update it.):
web_1 | 3: <head>
web_1 | 4: <title><%= content_for?(:html_title) ? yield(:html_title) : "Japanepa.com" %></title>
web_1 | 5: <%= csrf_meta_tags %>
web_1 | 6: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
web_1 | 7: <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
web_1 | 8: <%= Gon::Base.render_data %>
web_1 | 9: <%= include_gon %>
Autoprefixer doesn’t support Node v4.8.2. "The thing that automatically adds Vender Prefixes is that the Gem called Autoprefixer doesn't support Node v4.8.2."
Ruby on Rails - Autoprefixer doesn’t support Node v4.9.1. Update it. How to fix? It seems that it can be fixed by inserting a gem called "mini_racer"
Autoprefixer doesn’t support Node v4.8.2. Update it
#Change before
RUN apt-get update -qq \ && apt-get install -y nodejs postgresql-client
#After change
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*
Your Ruby version is 2.5.8, but your Gemfile specified 2.5.1 Error caused by different version of ruby However, the gemfile and dockerfile said:
source 'https://rubygems.org'
ruby '2.5.1'
FROM ruby:2.5.1
When I looked it up, the only solution was to match the ruby versions in the Gemfile and Dockerfile. Therefore, take the following countermeasures
"Uninstall and reinstall docker"
In fact, this solved the problem, but I can't recommend it in a too aggressive way.
I'm not very familiar with docker, but if the ruby image is pulled, will it be used regardless of the ruby version described in the Dockerfile? ??
I didn't understand the difference between docker-compose ʻup,
build and
start`, so I summarized it
What is a cache? Once you build Docker, a cache is created. As you know, browsers such as Google Chrome have the same function. If you have a cache, you can process it quickly when you build it from the second time onwards.
However, there are times when it is inconvenient to have a cache, such as when updating a Dockerfile. If you don't add the --no-cache option as introduced above, Docker will use the cache to build the image, so you won't see the updated Dockerfile and you won't be able to create a new image.
After all, it seems that a version difference error occurred because the cache when launching the container with the previous ruby 2.5.8 remained.
#Docker without using cache-compose.Pull a new image with the ruby version specified by yml
$ docker-compose build --no-cache
Delete old image
#Show a list of docker images
$ docker images
> REPOSITORY TAG IMAGE ID CREATED SIZE
> ruby 2.5.1 3c8181e703d2 22 months ago 869MB
#Delete image by specifying IMAGE ID
$ docker rmi 3c8181e703d2
that's all
Recommended Posts