If you're following along in 2019 or later, and you get an error when running `gem install rails`, you need to be starting docker with a later version of Ruby than what he's doing here, with a command like `docker run --rm -it -v "$PWD:/app" ruby:2.5 bash` , or whatever version the rails website says is the current minimum latest version for ruby.
@Coderjourney5 жыл бұрын
Thanks for this. I’ve pinned the comment so others can find it more easily.
@lizcooper96875 жыл бұрын
Thanks - exactly what I was looking for. This is the best example of networking an app and db in Docker I ‘ve seen.
@Coderjourney5 жыл бұрын
Awesome, I’m glad you found it useful.
@C0PED0GG8 жыл бұрын
Shared, Liked, Subscribed. Thanks for the video, please keep making them, they are clear and concise.
@Coderjourney8 жыл бұрын
+Max Copley Thanks for the support. I've been working on courses diving deeper into Docker at courses.coderjourney.com
@gabrielecalvo56976 жыл бұрын
In case you are running Docker on Windows and you get a weird "C:\Program Files\Docker Toolbox\docker.exe: invalid reference format: repository name must be lowercase." make sure "$PWD:/usr/src/app" is surrounded by quotes (unlike in the video at 13:30).
@cosmic99744 жыл бұрын
I seem to be getting this error... Tried to find answers on google but none worked. C:/Program Files/Docker Toolbox/docker.exe: Error response from daemon: invalid mode: \Users\justi\AppData\Local\Programs\Git\app. See 'C:/Program Files/Docker Toolbox/docker.exe run --help'.
@sameeraappana73785 жыл бұрын
What if I don't want to use POSTGRES but continue with sqlite3. How to write a Dockerfile then??
@Coderjourney5 жыл бұрын
Install sqlite instead of Postgres, and adjust your application code and dependencies accordingly.
@donjciii6 жыл бұрын
Keith, thank you very much for this tutorial, very well explained and put together! Shared, liked and subscribed a long time ago :-)
@Coderjourney6 жыл бұрын
Thank you. I’m glad you liked it, and I appreciate the support.
@ToddEmpcke7 жыл бұрын
Thanks for the tutorial however clearly I missed something. you did not use sudo while executing docker run, then in bash you were root when you executed rails, which if you use ls -al (for me at least) makes all of the generated files owned by root. So in atom when I try to modify one of those files I can't because they are owned by root. You did not seem to have an issue, and no one else has commented so please let me know where I went wrong?
@ToddEmpcke7 жыл бұрын
In case someone else has this issue, I solved it by adding `--user 1000:1000` to the docker run command, though I'd still like to know how it worked for the author of this tutorial... Note that the first 1000 is the user id, and the 2nd 1000 is the group id, so if your user and group id's are different you will have to use those instead.
@Coderjourney7 жыл бұрын
Thanks for reaching out. I just did this again with a stock virtualbox docker-machine and also ran into some issues. Not sure where the changes happened between recording this and now. Good catch. I did set up a machine using docker-machine-nfs and that mapped the ownership properly so I was back in working order.
@PaulSukys7 жыл бұрын
Todd Empcke, if your user is in docker group, you don't need root permissions for executing docker commands.
@dannunziostefano75597 жыл бұрын
Great tutorial....... Any chance on a tutorial on how to forward ssh key to a container, so docker can pull from private repos?
@Coderjourney7 жыл бұрын
+Dannunzio Stefano thank you! Forwarding your ssh key is a little tricky, but the short version is to pass through your ~/.ssh directory and then start the ssh agent within the container (in the background).
@cloudsben8 жыл бұрын
讲解真的很不错,通过教程 docker 就这样学会了
@Sonekkah5 жыл бұрын
Very well explained. I watched alongside learndocker.online and it was easy to understand.
@birharf65655 жыл бұрын
sure you did ! advertisement
@scrambledoracle7 жыл бұрын
CoderJourney thanks for this video. One problem that I keep encountering is that my shared volume is owned by root which prevents other resources from accessing the files. Any advice you can throw my way?
@Coderjourney7 жыл бұрын
By other resources do you mean other containers or something else?
@scrambledoracle7 жыл бұрын
I mean services running within the container. In my case, I'm attempting to set up my first PHP dev environment. I'm mapping my application directory to my host. NGINX (within the container) cannot read the mapped volume because docker is setting ownership to root when mapping.
@Coderjourney7 жыл бұрын
What user are you using inside of your container? I don't know that they've given a good way to get around this, but here's an issue that has a few possible workarounds github.com/docker/compose/issues/3270#issuecomment-206214034
@scrambledoracle7 жыл бұрын
Sorry, I don't know what specifically you are referring to when asking what I am running within the container. You said that you're not sure if there is a workaround to this which leads me to believe that this is normal and that I may be going about my setup incorrectly. However, NGINX shouldn't be running as root - which would grant it access to my shared volume.
@Coderjourney7 жыл бұрын
I asked what "user" you were using. You would need to explicitly set this for it to be something other than root. If you did (which is fine), then you'll likely need to `chown` the directory that you're mapping your volume to (as the root user, to the user you'd like NGINX to use). Since containers run as root by default, you can sometimes run into issues when you try to do the right thing and use a less privileged user.
@NamNguyen-sg4rq8 жыл бұрын
Hi, I follow your tutorial on window, everything works fine, except that when I refresh localhost:3000, it doesn't work (This site can’t be reached). Do you have any suggestion?. And where does /usr/src/app come from, I have a error relating to this in part 2(invalid bind mount spec "C:\\Users\\..\\.docker-dev\\blog:/usr/src/app:rw": invalid volume specification: 'C:\Users\..\docker-dev\blog:/usr/src/app:rw'). Thank you.
@NamNguyen-sg4rq8 жыл бұрын
1. I need to use docker ip in stead of localhost 2. The problem was I didn't set the environment variable COMPOSE_CONVERT_WINDOWS_PATHS
@Coderjourney8 жыл бұрын
+Hải Nam Nguyễn sorry these tutorials aren't 100% accurate when following along on Windows. I'm glad you got it figured out.
@LiaAdzumi8 жыл бұрын
Hi, After following closely your tutorial (I spent 2 days on this single video), which is very hard to follow on Windows, I could manage up to here "C:\Users\ing\app\blog>docker build -t blog ." But, I could not continue it because I got this message "'export' is not recognized as an internal or external command, operable program or batch file.", after executing this command "export POSTGRES_USER="ing" " You are doing good, but not for a beginners who are using Windows like myself. You jumped from one terminal to another terminal, moved from a directory to different directory without clear explanation. There are a lot smart people like you published video tutorials, but they might not think about who the absolute beginners. But I still thanks for your efforts to teach us. So, please do make a very clear explanation in every step of your movement. So, can you or any body help me to solve the above problem? Thanks.
@Coderjourney8 жыл бұрын
+Duta Ksp I apologize for going through things too quickly, at a certain point I have to draw the line between what I explain and what I don't in order to keep the videos to a reasonable length. Thanks for sticking with this and reaching out, I need to do a better job of keeping windows in mind. I do have a few videos on command line usage if those would be helpful (although again they are unix oriented). Onto your problem, "export" is used to create environment variables on a unix based machine, the equivalent in windows is "set". Replace "export" with "set" in those commands. From there you'll want to use those slightly differently when passing them to your containers. Since you have them set on your machine you should be able use: docker run -d -e POSTGRES_USER -e POSTGRES_PASSWORD (Followed by the rest of the command) Let me know if you run into any more issues.
@kelvinromero7 жыл бұрын
Hi CoderJourney, I'm having a little trouble here. The container worked at first, but I got no response in the browser. I tried to analyse the network but wasn't sure what to look for. I tried to remove the container then run it again, but I'm getting a error (That rails is server is already running). I'm using boot2docker. And I'm not sure what the network should looks like on Virtualbox, Docker-machine and Windows (I used netstat to check for the port 3000, and wasn't there)
@Coderjourney7 жыл бұрын
What address are you trying to connect to in the browser?
@kelvinromero7 жыл бұрын
I tried localhost and also the 192.168.99.100 address (assigned to eth1 iface in the docker-machine) which I can ping to, from windows. The other adresses are in a completily different network, 172.0.0.0/16 and 10.0.0.0/8.
@Coderjourney7 жыл бұрын
+Kelvin Romero it should be 192.168.99.100. When you 'docker ps' do you see that the port is routing properly? Should see something like 0.0.0.0:3000 -> 3000
@kelvinromero7 жыл бұрын
In addition to that, I ran the app container in the interactive mode. Even though I previously deleted the container it kept given this error that the server is already running. The solution to that was delete tmp/pids/server.pid.
@Coderjourney7 жыл бұрын
Yeah, that issue is resolved in a later tutorial by using a script to start the app (see here if you're interested github.com/coderjourney/meal_plan/commit/11c5fdb138fcb9e76270c6f93dfbc160b96c2bca) When you're starting rails are you binding to `0.0.0.0` by using the -b flag?
@TroyMurray7 жыл бұрын
Another great job on showing to use Docker. I did run into an issue and wanted to share. Where you had us create the welcome_controller.rb file and render the text, this didn't work on Rails 5.1.3, as it was looking for a view file for the show action and puma would throw an error. I created the file app/views/welcome/show.html.erb and then the page displayed correctly.
@Coderjourney7 жыл бұрын
Good catch. The 'text' handler type was removed. The equivalent would be `render plain: 'Hello from Docker'` now.
@makarnautovic4347 жыл бұрын
Should you or anyone else experience that issue again, you can use `render html:` instead of `render text`' in the controller without having to create the view.
@VolodymyrKuchinskyi-z7u6 жыл бұрын
Nice work, very informational content ))
@bradchellingworth59737 жыл бұрын
Perhaps i missed a step here, but it seems you pass a db user and password and use it to create the database, but at no point to we set that user up in postgres? I just errors at that point saying role doesn't exist and I cant get my head around how you can create a db without having set up a user first? When creating the db we should do something like CREATE ROLE new_user WITH CREATEDB CREATEROLE SUPERUSER;
@Coderjourney7 жыл бұрын
This threw me off the first time I messed with the postgres image. The docs (found at hub.docker.com/_/postgres) tell you that setting these environment variables will work, and it actually happens within a script in the postgres image. Here are the lines specifically github.com/docker-library/postgres/blob/913bc48bfdccab58c6c15f11841da5146e7bf968/9.6/docker-entrypoint.sh#L98-L117
@bradchellingworth59737 жыл бұрын
Ah ok that makes sense, I named my env vars DB_USER / DB_PASS, So I guess I need to specifically call them POSTGRES_USER / POSTGRES_PASSWORD. That helps, thank you for the very swift and informative reply.
@bradchellingworth59737 жыл бұрын
Hi, sorry one more question, any ideas why I'm not seeing changes made in controller being reflected? So at 15:17 that works fine, but then go back and edit that text, the change doesn't get reflected? I have posted on SO stackoverflow.com/questions/43138983/rails-controller-caching-when-using-docker-container-dev Thanks again
@Coderjourney7 жыл бұрын
No apologies necessary. If you're familiar with using a terminal based text editor you can see if the file system watcher is working properly by running `docker-compose exec app bash` and then editing the file from within the container and seeing if that updates for you. If not then there's an issue with the watcher. Beyond that it's a little hard for me to diagnose without being able to poke around. Are you developing from Windows, Mac, or Linux?
@Coderjourney7 жыл бұрын
At the very least you can verify that your updates are reflected within the container by running `docker-compose exec app cat app/controllers/something_controller.rb` (I don't actually remember what the controller name is...)
@AravindKumar-vi4ul7 жыл бұрын
Hi CoderJourney, Your videos about dockers are superb. I don't understand the usage and context of the following command which you've ran, docker run --rm .... -net=blog blog rake db:setup
@Coderjourney7 жыл бұрын
+Aravind Kumar Hi! That is a one-off command that will run "rake db:setup" in a "blog" container and then remove the container. We need to have our database before actually running the application.
@AravindKumar-vi4ul7 жыл бұрын
is it possible to run those commands while starting container. do you have any article regarding this in your blog
@Coderjourney7 жыл бұрын
+Aravind Kumar it is possible, you would wed to specify a script as your container command and have the script setup the database as well as run the application server. You can see an example script here github.com/coderjourney/meal_plan/blob/master/script/start
@AravindKumar-vi4ul7 жыл бұрын
CoderJourney thank you
@Coderjourney7 жыл бұрын
+Aravind Kumar you're welcome
@RellonLawrence7 жыл бұрын
Can you help me with this error? ERROR: for app Cannot start service app: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"rails server -b 0.0.0.0\": executable file not found in $PATH": unknown
@Coderjourney7 жыл бұрын
What does your Dockerfile look like?
@RellonLawrence7 жыл бұрын
FROM ruby RUN apt-get update -yqq \ && apt-get install -yqq postgresql-client \ && rm -rf /var/lib/apt/lists WORKDIR /usr/src/app COPY Gemfile* . RUN bundle install COPY . . EXPOSE 3000 CMD rails server -b 0.0.0.0
@Coderjourney7 жыл бұрын
Weird, that looks normal to me. What docker command are you using when you get this error?
@RellonLawrence7 жыл бұрын
docker-compose up
@carloslora97838 жыл бұрын
Error response from daemon: create $PWD: "$PWD" includes invalid characters for a local volume name | 2:40
@Coderjourney8 жыл бұрын
+Carlos Lora What's the exact command that you used? The portion of the volume declaration after the ":" needs to be a path that starts with a "/" character. My example is "$PWD:/app" where the "$PWD" will evaluate on your system and docker will create the "/app" directory within the container.
@carloslora97838 жыл бұрын
Fix, on windows is different, in my case is: docker run --rm -it -v /c/Users/username/app:/app ruby:2.3 bash , Remember activate the /C/ share drives in the docker setting app
@Coderjourney8 жыл бұрын
+Carlos Lora Ah that makes sense. I need to be more testing in Windows so I'm more aware of the differences. Thanks for bringing this to my attention.
@patrickkuhn50747 жыл бұрын
As from rails 4.1 rails deprecated 'render text:'. Use 'render html:' instead.
@Coderjourney7 жыл бұрын
+Patrick Kühn to render plain text like we were you’ll want to use ‘render plain:’ instead.
@starvingdeveloper29878 жыл бұрын
Awesome tutorial, thanks a lot for this. New subscriber
@Coderjourney8 жыл бұрын
+Starving Developer thanks a lot. I'm glad you're liking the videos. If you've got any questions or suggestions please send them my way.