Docker, in the beginning, can be overwhelming. Tutorials often focus on creating a complex interaction between Dockerfiles, docker-compose, entrypoint scripts and networking.
It can take hours to bring up a simple Rails application in Docker and I found that put me off the first few times I tried to play with it.
I think a rapid feedback loop is essential for playing with a piece of technology.
If you've never used Docker before, then this is the perfect post for you. I'll start you off on your docker journey and with a few simple commands, you'll be in a Docker container, running ruby interactively.
You'll need to install Docker. On a Mac, I prefer to install Docker Desktop through homebrew:
brew cask install docker
If you're running Linux or Windows, read the official docs for install instructions.
On your Mac, you should now have a Docker icon in your menu bar. Click on it and make sure it says "Docker desktop is running".
Now open a terminal and type the following:
$ docker run -it --rm ruby:2.7.1-buster
You should be dropped into an irb session:
> docker run -it --rm ruby:2.7.1-buster
irb(main):001:0> puts "Hello from inside a Docker container"
Hello from inside a Docker container
=> nil
irb(main):002:0>
That should return you to your normal command prompt.
It doesn't look like you've done much - bringing up an irb session isn't groundbreaking. You can do the same by typing irb at your usual prompt.
Breaking down the command used:
docker run
runs a command in a new container
-it
these two options that tell docker to run in interactive mode and to allocate a pseudo-TTY
--rm
instructs docker to automatically delete the container when we exit
ruby:2.7.1-buster
theimage that we want to run.
You'll notice that none of those commands actually tried to execute irb to run the Ruby REPL. So how did we end up in an irb session?
The answer is that the Docker image we used defined a default step for us to start irb.
Top comments (0)