Docker Rails Tutorial generated files not exists - ruby-on-rails

I am trying basic Docker & Rails tutorials on my windows10 home OS with Docker toolbox.
Client: 17.05.0-ce
Server: 17.06.0-ce
And hello-world tutorials works!
Now I am trying this youtube tutorial: https://www.youtube.com/watch?v=KH6pcHb6Wug&lc=z12ocxayznynslzjj04chbtgiwbhuf4z5xk0k.1499518307572479
And everything looks okay until I check rails generated project files.
In terminal showing like files are generating but when I use the command 'ls -l' its show only my manually created files (4).
What's happening with Rails generated files?
Where they go?
Here is docker-compose.yml content:
version: '2'
services:
db:
image: postgres
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/deep
ports:
- "3000:3000"
depends_on:
- db
Here is Dockerfile content:
FROM ruby:2.3.3
ENV HOME /home/rails/deep
# Install PGsql dependencies and js engine
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
WORKDIR $HOME
# Install gems
ADD Gemfile* $HOME/
RUN bundle install
# Add the app code
ADD . $HOME
Here is my terminal at end: https://ibb.co/c2eqFF
I found the solution:
https://github.com/laradock/laradock/issues/508
Just need to place a .env file next to your docker-compose.yml file, with the following content : COMPOSE_CONVERT_WINDOWS_PATHS=1

I found the solution: https://github.com/laradock/laradock/issues/508
Just need to place a .env file next to your docker-compose.yml file, with the following content : COMPOSE_CONVERT_WINDOWS_PATHS=1

Related

The path `/app/include/engine` does not exist. (Bundler::PathError)

I am dockerizing my rails app with the mountable engine. But I am constantly getting one error while running the image The path `/app/include/engine` does not exist.
The image is successfully built but while running docker-compose up it throws an error of the path.
Below I am attching my Dockerfile and docker-compose.yml
Dockerfile
FROM ruby:2.4.1
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /app
WORKDIR /app
ADD Gemfile /app/Gemfile
ADD Gemfile.lock /app/Gemfile.lock
COPY . .
RUN mkdir -p /app/include/engine
RUN git clone git#github.com:engine/engine.git /app/include/engine
RUN ls
RUN ls /app/include/engine
RUN DISABLE_SSL=true gem install puma -v 3.6.0
RUN bundle check || bundle install
CMD ["rails", "server", "-b", "0.0.0.0"]
docker-compose.yml
version: '2'
services:
db:
image: mysql:8.0.21
restart: always
environment:
MYSQL_ROOT_PASSWORD: root#123
MYSQL_DATABASE: prod
MYSQL_USER: root
MYSQL_PASSWORD: root#123
ports:
- "3307:3306"
app:
build:
context: .
dockerfile: Dockerfile
args:
SSH_PRIVATE_KEY: ${SSH_PRIVATE_KEY}
volumes:
- ".:/app"
ports:
- "3000:3000"
depends_on:
- db
environment:
key: value
I have also included my engine path in Gemfile and followed all the steps in mounting engine
# engine
gem 'api', path: 'include/engine'
It works fine in the local environment but it gives me an error in docker.
Can someone please help what I m missing somewhere?
it because of this line
volumes:
- ".:/app"
This mounts your local dir inside the container when starting overwriting existing data already in the image. This means everything in /app is replaced with data from your local machine including your engine /app/include/engine.
To fix this you need to have this engine cloned in your local folder so it is available when starting the container. An other option is to clone the engine outside /app for example in /tmp or whatever you like.

Docker - correct approach for cms development

I am currently setting up docker for development purpose.
The goal would be to easily setup mysql, apache, php, and the cms (Omeka).
I managed to rewrite a dockerfile and dockercompose that automatically setup the cms for a normal user, but i need to be able to access the CMS source code i wget'd during build.
From my understanding, volumes/binds aren't the solution because they only access files added after build (i tried anyway and couldn't access the files).
Should i write a script the run the compose routine, and then download the files and do the things necessary for installing the cms, or is there a more docker approach to this ?
Here is my docker-compose :
version: '3'
services:
db:
image: mysql:latest
environment:
//some vars. irrelevant
phpmyadmin:
image: phpmyadmin/phpmyadmin
depends_on:
- db
ports:
- 8081:80
omeka:
build: .
depends_on:
- db
ports:
- "8080:80"
environment:
//some vars. Irrelevant
volumes:
- type: bind
source: ./www/
target: /var/www/
volumes:
www:
And my Dockerfile :
FROM php:8.0.3-apache
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y --no-install-recommends \
[some packages]
RUN docker-php-ext-install exif mysqli
# Install omeka
WORKDIR /var/www
RUN git clone --recursive https://github.com/omeka/Omeka.git
RUN chown -R root.www-data Omeka && chmod 775 Omeka
WORKDIR /var/www/Omeka
[....]
# Copy some files, run some commands, set some rights
# Configure apache
COPY omeka.conf /etc/apache2/sites-available/omeka.conf
[....]
# Configure php
[...]
# Add init script
COPY run.sh /run.sh
RUN dos2unix "/run.sh"
RUN chmod 755 /*.sh
EXPOSE 443
CMD ["/run.sh"]
Running this (i removed some vars, and of course config files are lacking for clarity purposes) gives me a www folder that stays empty.
I don't quite understand how i could do this, as i don't exactly know how the files are persistent or not when re-running docker-compose p -d
This is my first docker file as well.
Thank you

Docker Permission denied

I am trying to create an rails application through docker.
my docker-compose.yml file is :
mysql:
image: mysql:5.6.34
ports:
- "3006:3006"
volumes_from:
- dbdata
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=dev
dbdata:
image: tianon/true
volumes:
- /var/lib/mysql
app:
build: .
environment:
RAILS_ENV: development
ports:
- '3000:3000'
volumes_from:
- appdata
links:
- "mysql"
appdata:
image: tianon/true
volumes:
- ".:/dock_rails_1"
Dockerfile is :
FROM ruby:2.3.3
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs mysql-client
RUN mkdir /dock_rails_1
WORKDIR /dock_rails_1
COPY Gemfile /dock_rails_1/Gemfile
COPY Gemfile.lock /dock_rails_1/Gemfile.lock
RUN bundle install
COPY . /dock_rails_1
My Gemfile is :
source 'https://rubygems.org'
gem 'rails', '5.0.0.1'
I have also created the empty Gemfile.lock.
After this run this command in my terminal:
docker-compose run app rails new . --force --database=mysql --skip-bundle
Every thing goes right. But I don't have edit acess to all the files created by docker.
When I am trying to edit the database.yml file created by docker it is telling permission denied.
Please help me why I am unable to edit my files.
Just making a few assumptions here, hope I'm right..
Probably, the user you use inside the container is root
and the file is created under root privileges.
Try to create and use a user with the same uid and gid as in your host machine.
you can find out your hosts uid/gid by running on your host:
cat /etc/passwd | grep $USER
change the containers user to hosts uid and gid in your docker file:
RUN usermod -u my_users_host_uid container_user
RUN groupmod -g my_users_host_gid container_user

How to install packages from Docker compose?

Hi there I am new to Docker. I have an docker-compose.yml which looks like this:
version: "3"
services:
lmm-website:
image: lmm/lamp:php${PHP_VERSION:-71}
container_name: ${CONTAINER_NAME:-lmm-website}
environment:
HOME: /home/user
command: supervisord -n
volumes:
- ..:/builds/lmm/website
- db_website:/var/lib/mysql
ports:
- 8765:80
- 12121:443
- 3309:3306
networks:
- ntw
volumes:
db_website:
networks:
ntw:
I want to install the Yarn package manager from within the docker-compose file:
sudo apt-get update && sudo apt-get install yarn
I could not figure out how to declare this, I have tried
command: supervisord -n && sudo apt-get update && sudo apt-get install yarn
which fails silently. How do I declare this correctly? Or is docker-compose.yml the wrong place for this?
Why not use Dockerfile which is specifically designed for this task?
Change your "image" property to "build" property to link a Dockerfile.
Your docker-compose.yml would look like this:
services:
lmm-website:
build:
context: .
dockerfile: Dockerfile
container_name: ${CONTAINER_NAME:-lmm-website}
environment:
HOME: /home/user
command: supervisord -n
volumes:
- ..:/builds/lmm/website
- db_website:/var/lib/mysql
ports:
- 8765:80
- 12121:443
- 3309:3306
networks:
- ntw
volumes:
db_website:
networks:
Then create a text file named Dockerfile in the same path as docker-compose.yml with the following content:
FROM lmm/lamp:php${PHP_VERSION:-71}
RUN apt-get update && apt-get install -y bash
You can add as much SO commands as you want using Dockerfile's RUN (cp, mv, ls, bash...), apart from other Dockerfile capabilities like ADD, COPY, etc.
+info:
https://docs.docker.com/engine/reference/builder/
+live-example:
I made a github project called hello-docker-react. As it's name says is a docker-react box, and can serve you as an example as I am installing yarn plus other tools using the procedure I explained above.
In addition to that, I also start yarn using an entrypoint bash script linked to docker-compose.yml file using docker-compose entrypoint property.
https://github.com/lopezator/hello-docker-react
You can only do it with a Dockerfile, because the command operator in docker-compose.yml only keeps the container alive during the time the command is executed, and then it stops.
Try this
command: supervisord -n && apt-get update && apt-get install yarn
Because sudo doesn't work in docker.
My first time trying to help out:
would like you to give it a try (I found it on the internet)
FROM lmm/lamp:php${PHP_VERSION:-71}
USER root
RUN apt-get update && apt-get install -y bash

getting bundler load error frequently and no such file Gemfile error

Below is the docker file in project's root directory:-
FROM ruby:2.2
MAINTAINER technologies.com
RUN apt-get update -qq && apt-get install -y build-essential
RUN apt-get install -y libxml2-dev libxslt1-dev
RUN apt-get install -y libqt4-webkit libqt4-dev xvfb
RUN apt-get install -y nodejs
ENV INSTALL_PATH /as_app
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY Gemfile Gemfile
RUN bundle install
COPY . .
EXPOSE 3000
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
Below is the contents in docker-compose.yml file in project's root directory :-
as_web:
build: .
environment:
- RAILS_ENV=development
- QUEUE=*
- REDIS_URL=redis://redis:6379
volumes:
- .:/as_app
ports:
- 3000:3000
links:
- as_mongo
- as_redis
command: rails server -b 0.0.0.0
as_mongo:
image: mongo:latest
ports:
- "27017:27017"
as_redis:
image: redis
ports:
- "6379:6379"
as_worker:
build: .
environment:
- QUEUE=*
- RAILS_ENV=development
- REDIS_URL=redis://redis:6379
volumes:
- .:/as_app
links:
- as_mongo
- as_redis
command: bundle exec rake environment resque:work
docker version 1.11.2, docker-machine version 0.8.0-rc1, docker-compose version 1.8.0-rc1, ruby 2.2.5, rails 4.2.4.
My problem is as:-
1) When I build the image with "docker-compose build" from project root directory the image builds successfully with gems installed.
2) But when I do "docker-compose up" the as_web and as_worker services exits with code 1 and 10 resp. giving error as no gemfile or .bundler found. When I login in image through bash and see the working directory then no project files are seen.
3) Knowledge I want to know is:-
i) when I start terminal, I start VirtualBox instance manually like "docker-machine start default"
ii) Then I execute command "eval $(docker-machine env dev)" to point current shell to virtualbox docker-daemon, So after this when i do "docker build -t as_web ." the terminal gives message like "sending current build context to docker daemon",
a) Is this message saying that build in being done in VirtualBox ?
if I do "docker-compose build" no such message like "sending...." appears,
B) Does docker-compose too point to docker daemon in virtual box or it's being build in localhost(myubuntuOS), I'm little bit confused?
Hoping you guys understood the details if you need any extra info. then let me know, Thanking you all. Happy Coding.
docker-compose build and docker build both do the same thing. They both use the docker engine API to build an image in the virtualbox. The output messages are just a little different.
Your problem is because of this:
volumes:
- .:/as_app
You're overriding the app directory with the project directory from the host. If you haven't run bundle install on the host, the files won't be in the container when it starts.
You can fix this by running docker-compose run as_app bundle install

Resources