Просмотр исходного кода

fix(create): Improve example dockerfile & docs

Michael Bromley 3 лет назад
Родитель
Сommit
86770d1db7
2 измененных файлов с 17 добавлено и 2 удалено
  1. 1 1
      packages/create/templates/Dockerfile.hbs
  2. 16 1
      packages/create/templates/readme.hbs

+ 1 - 1
packages/create/templates/Dockerfile.hbs

@@ -4,6 +4,6 @@ WORKDIR /usr/src/app
 
 COPY package.json ./
 COPY {{#if useYarn}}yarn.lock{{else}}package-lock.json{{/if}} ./
-RUN {{#if useYarn}}yarn{{else}}npm install{{/if}}
+RUN {{#if useYarn}}yarn{{else}}npm install{{/if}} --production
 COPY . .
 RUN {{#if useYarn}}yarn{{else}}npm run{{/if}} build

+ 16 - 1
packages/create/templates/readme.hbs

@@ -55,7 +55,8 @@ We've included a sample [Dockerfile](./Dockerfile) which you can build with the
 docker build -t vendure .
 ```
 
-and then run it with:
+This builds an image and tags it with the name "vendure". We can then run it with:
+
 ```
 # Run the server
 docker run -dp 3000:3000 -e "DB_HOST=host.docker.internal" --name vendure-server vendure npm run start:server
@@ -64,6 +65,20 @@ docker run -dp 3000:3000 -e "DB_HOST=host.docker.internal" --name vendure-server
 docker run -dp 3000:3000 -e "DB_HOST=host.docker.internal" --name vendure-worker vendure npm run start:worker
 ```
 
+Here is a breakdown of the command used above:
+
+- `docker run` - run the image we created with `docker build`
+- `-dp 3000:3000` - the `-d` flag means to run in "detached" mode, so it runs in the background and does not take
+control of your terminal. `-p 3000:3000` means to expose port 3000 of the container (which is what Vendure listens
+on by default) as port 3000 on your host machine.
+- `-e "DB_HOST=host.docker.internal"` - the `-e` option allows you to define environment variables. In this case we
+are setting the `DB_HOST` to point to a special DNS name that is created by Docker desktop which points to the IP of
+the host machine. Note that `host.docker.internal` only exists in a Docker Desktop environment and thus should only be
+used in development.
+- `--name vendure-server` - we give the container a human-readable name.
+- `vendure` - we are referencing the tag we set up during the build.
+- `npm run start:server` - this last part is the actual command that should be run inside the container.
+
 ### Docker compose
 
 We've included a sample [docker-compose.yml](./docker-compose.yml) file which demonstrates how the server, worker, and