Learn to use Docker in Development - Part 1

  Рет қаралды 44,611

CoderJourney

CoderJourney

Күн бұрын

Пікірлер: 80
@jeffmjack
@jeffmjack 5 жыл бұрын
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.
@Coderjourney
@Coderjourney 5 жыл бұрын
Thanks for this. I’ve pinned the comment so others can find it more easily.
@lizcooper9687
@lizcooper9687 5 жыл бұрын
Thanks - exactly what I was looking for. This is the best example of networking an app and db in Docker I ‘ve seen.
@Coderjourney
@Coderjourney 5 жыл бұрын
Awesome, I’m glad you found it useful.
@C0PED0GG
@C0PED0GG 8 жыл бұрын
Shared, Liked, Subscribed. Thanks for the video, please keep making them, they are clear and concise.
@Coderjourney
@Coderjourney 8 жыл бұрын
+Max Copley Thanks for the support. I've been working on courses diving deeper into Docker at courses.coderjourney.com
@gabrielecalvo5697
@gabrielecalvo5697 6 жыл бұрын
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).
@cosmic9974
@cosmic9974 4 жыл бұрын
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'.
@sameeraappana7378
@sameeraappana7378 5 жыл бұрын
What if I don't want to use POSTGRES but continue with sqlite3. How to write a Dockerfile then??
@Coderjourney
@Coderjourney 5 жыл бұрын
Install sqlite instead of Postgres, and adjust your application code and dependencies accordingly.
@donjciii
@donjciii 6 жыл бұрын
Keith, thank you very much for this tutorial, very well explained and put together! Shared, liked and subscribed a long time ago :-)
@Coderjourney
@Coderjourney 6 жыл бұрын
Thank you. I’m glad you liked it, and I appreciate the support.
@ToddEmpcke
@ToddEmpcke 7 жыл бұрын
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?
@ToddEmpcke
@ToddEmpcke 7 жыл бұрын
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.
@Coderjourney
@Coderjourney 7 жыл бұрын
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.
@PaulSukys
@PaulSukys 7 жыл бұрын
Todd Empcke, if your user is in docker group, you don't need root permissions for executing docker commands.
@dannunziostefano7559
@dannunziostefano7559 7 жыл бұрын
Great tutorial....... Any chance on a tutorial on how to forward ssh key to a container, so docker can pull from private repos?
@Coderjourney
@Coderjourney 7 жыл бұрын
+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).
@cloudsben
@cloudsben 8 жыл бұрын
讲解真的很不错,通过教程 docker 就这样学会了
@Sonekkah
@Sonekkah 5 жыл бұрын
Very well explained. I watched alongside learndocker.online and it was easy to understand.
@birharf6565
@birharf6565 5 жыл бұрын
sure you did ! advertisement
@scrambledoracle
@scrambledoracle 7 жыл бұрын
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?
@Coderjourney
@Coderjourney 7 жыл бұрын
By other resources do you mean other containers or something else?
@scrambledoracle
@scrambledoracle 7 жыл бұрын
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.
@Coderjourney
@Coderjourney 7 жыл бұрын
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
@scrambledoracle
@scrambledoracle 7 жыл бұрын
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.
@Coderjourney
@Coderjourney 7 жыл бұрын
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-sg4rq
@NamNguyen-sg4rq 8 жыл бұрын
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-sg4rq
@NamNguyen-sg4rq 8 жыл бұрын
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
@Coderjourney
@Coderjourney 8 жыл бұрын
+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.
@LiaAdzumi
@LiaAdzumi 8 жыл бұрын
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.
@Coderjourney
@Coderjourney 8 жыл бұрын
+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.
@kelvinromero
@kelvinromero 7 жыл бұрын
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)
@Coderjourney
@Coderjourney 7 жыл бұрын
What address are you trying to connect to in the browser?
@kelvinromero
@kelvinromero 7 жыл бұрын
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.
@Coderjourney
@Coderjourney 7 жыл бұрын
+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
@kelvinromero
@kelvinromero 7 жыл бұрын
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.
@Coderjourney
@Coderjourney 7 жыл бұрын
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?
@TroyMurray
@TroyMurray 7 жыл бұрын
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.
@Coderjourney
@Coderjourney 7 жыл бұрын
Good catch. The 'text' handler type was removed. The equivalent would be `render plain: 'Hello from Docker'` now.
@makarnautovic434
@makarnautovic434 7 жыл бұрын
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-z7u
@VolodymyrKuchinskyi-z7u 6 жыл бұрын
Nice work, very informational content ))
@bradchellingworth5973
@bradchellingworth5973 7 жыл бұрын
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;
@Coderjourney
@Coderjourney 7 жыл бұрын
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
@bradchellingworth5973
@bradchellingworth5973 7 жыл бұрын
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.
@bradchellingworth5973
@bradchellingworth5973 7 жыл бұрын
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
@Coderjourney
@Coderjourney 7 жыл бұрын
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?
@Coderjourney
@Coderjourney 7 жыл бұрын
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-vi4ul
@AravindKumar-vi4ul 7 жыл бұрын
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
@Coderjourney
@Coderjourney 7 жыл бұрын
+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-vi4ul
@AravindKumar-vi4ul 7 жыл бұрын
is it possible to run those commands while starting container. do you have any article regarding this in your blog
@Coderjourney
@Coderjourney 7 жыл бұрын
+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-vi4ul
@AravindKumar-vi4ul 7 жыл бұрын
CoderJourney thank you
@Coderjourney
@Coderjourney 7 жыл бұрын
+Aravind Kumar you're welcome
@RellonLawrence
@RellonLawrence 7 жыл бұрын
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
@Coderjourney
@Coderjourney 7 жыл бұрын
What does your Dockerfile look like?
@RellonLawrence
@RellonLawrence 7 жыл бұрын
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
@Coderjourney
@Coderjourney 7 жыл бұрын
Weird, that looks normal to me. What docker command are you using when you get this error?
@RellonLawrence
@RellonLawrence 7 жыл бұрын
docker-compose up
@carloslora9783
@carloslora9783 8 жыл бұрын
Error response from daemon: create $PWD: "$PWD" includes invalid characters for a local volume name | 2:40
@Coderjourney
@Coderjourney 8 жыл бұрын
+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.
@carloslora9783
@carloslora9783 8 жыл бұрын
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
@Coderjourney
@Coderjourney 8 жыл бұрын
+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.
@patrickkuhn5074
@patrickkuhn5074 7 жыл бұрын
As from rails 4.1 rails deprecated 'render text:'. Use 'render html:' instead.
@Coderjourney
@Coderjourney 7 жыл бұрын
+Patrick Kühn to render plain text like we were you’ll want to use ‘render plain:’ instead.
@starvingdeveloper2987
@starvingdeveloper2987 8 жыл бұрын
Awesome tutorial, thanks a lot for this. New subscriber
@Coderjourney
@Coderjourney 8 жыл бұрын
+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.
@EmilKarlsson
@EmilKarlsson 7 жыл бұрын
Nice work!
@Coderjourney
@Coderjourney 7 жыл бұрын
+Emil Karlsson thanks
@LucasAmoedo
@LucasAmoedo 7 жыл бұрын
Bro Thanks bro
@Coderjourney
@Coderjourney 7 жыл бұрын
You're welcome
@joshc3000
@joshc3000 5 жыл бұрын
Gross! Ruby?... WTF?
Learn to use Docker in Development - Part 2
9:11
CoderJourney
Рет қаралды 10 М.
Deploying a Rails Application with Docker
15:43
CoderJourney
Рет қаралды 23 М.
OCCUPIED #shortssprintbrasil
0:37
Natan por Aí
Рет қаралды 131 МЛН
Counter-Strike 2 - Новый кс. Cтарый я
13:10
Marmok
Рет қаралды 2,8 МЛН
Create a Development Environment with Docker Compose by Mark Ranallo
21:05
18 Weird and Wonderful ways I use Docker
26:18
NetworkChuck
Рет қаралды 477 М.
The intro to Docker I wish I had when I started
18:27
typecraft
Рет қаралды 382 М.
Dockerizing an Existing Rails Application
20:53
CoderJourney
Рет қаралды 27 М.
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 196 М.
Learn the Basics of Docker
14:51
CoderJourney
Рет қаралды 32 М.
Docker Для Начинающих за 1 Час | Docker с Нуля
52:43
Docker Swarm Mode Walkthrough
12:30
Elton Stoneman
Рет қаралды 126 М.