Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial docker file #15

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Conversation

seam345
Copy link

@seam345 seam345 commented Jun 7, 2019

- Summary
Initial pull request to iterate on with Joseph-allen #10

My docker file that I managed to get working at the meetup.

The two commands I used to get it running are below, I needed to run them as sudo but that was I accidentally installed docker as root.

  1. docker build -t my-nodejs-app .
  2. docker run -it --rm --net=host --name my-running-app my-nodejs-app

- Test plan
Sadly I have done no test, other than being able to load the homepage.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)
Couldn't resist putting a picture of Lexi when she was a puppy.
IMG_20120524_202738

@seam345 seam345 mentioned this pull request Jun 7, 2019
@vincelee888
Copy link
Member

nice one! does this allow people to edit the source code, and have it livereload within the docker container?

@joseph-allen
Copy link

not unless they edit the code within the docker container, they would have to rebuild and rerun manually sadly. we could have a script that does this bit automatically though?

we need a README update on this, and brief docker setup otherwise it's meaningless. I will add it in tomorrow :)

@vincelee888
Copy link
Member

vincelee888 commented Jun 8, 2019 via email

@joseph-allen
Copy link

I don't know enough about docker to answer that, this PR won't do that though. @jaspajjr any advice on this?

We can still merge this one and iterate on it for live reload.

@joseph-allen
Copy link

I don't have permission to push to Seans repo or this PR.

### Docker
If you want to setup the project with Docker and don't want to be reliant on any other setup phases build and run using:

docker build -t mhp .
docker run --net=host mhp


The site should then be hosted on https://localhost:3000

I propose adding the above to the README, not sure it's quite right though as Sean had the run command sorted. @seam345

@jaspajjr
Copy link

jaspajjr commented Jun 9, 2019

ah ok, i thought you could mount a drive within the container, that pointed to the source directory on your machine, then the livereload would kick in on file updates

I use a similar thing for running Vim in a docker container

docker run -ti --rm -v $(pwd):/home/developer/workspace jaspajjr/alpine-vim

The -v flag mounts a volume, which I think should work.

@seam345
Copy link
Author

seam345 commented Jun 10, 2019

I added everyone on this thread as collaborators to my forked version in case anyone wanted to make changes.
I have just ran the 2 command proposed by Joe to be put into the readme and they build and work on my laptop
Just having a quick look into what -v does now, I'll try add to the readme later hopefully with the live reloading, but I'll post back any updates.

@seam345
Copy link
Author

seam345 commented Jun 10, 2019

I'm unsure -v is the right option it allows accessing a folder from outside docker inside, not the other way round.. If i get some time tomorrow I'll have a longer look into this.

Updated the docker file to get live reloading to work.
Added the comands I ran to get the docker container to work
@seam345
Copy link
Author

seam345 commented Jun 11, 2019

I got it working with live reloading had to change the docker file quite a bit and the commands used to build and run was

docker build -t mhp .
docker run -v "$(pwd)":/app -w /app mhp npm install
docker run -v "$(pwd)":/app -w /app --net=host mhp npm run start

All the code stays in the folder you pulled it down into, docker is purely just running the code and not storing it inside the container at all.

@joseph-allen
Copy link

it seems to run fine but still won't render when I go to localhost:3000
Is it better to have live reloading when the purpose of this is to keep minimal setup?

@rml1997
Copy link

rml1997 commented Jun 19, 2019

Oops, I've written an alternative setup that does live reload. I'll open a new PR

@joseph-allen
Copy link

lets marry the best of both world.

Copy link

@rml1997 rml1997 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using -p should set the port to be published on the host, so you don't need to expose it in the image

I wouldn't bother building an image with so little in it as your latest commit. I'd just use the node image if you're going to do it like that.
docker run -p 3000:3000 -v "$(pwd)":/app -w /app --net=host node:10 npm run start
I've not tested the above because I'm on my windows box which doesn't support $(pwd)

I'd use node:10 rather than 10.1 so it can update. Shouldn't get any breaking changes on minor version increments.

I'd consider building an image, like your first commit, and using docker-compose up to simplify the process. This is mostly because of how hard it is to get the bind working properly. Due to docker not accepting . as a volume name and $(pwd) being bash only, I set up individual volumes for each subdirectory within the project, so livereload would work. It won't work for changes to the root of the project. so changes to package.json would require a rebuild of the image. This might be fixed by creating a bound volume for package.json although I think I tried this and it didn't seem to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants