Sign inSign up

uconn/local

By uconn

•Updated over 8 years ago

Image for local task running and asset management. Can be used with: gulp, webpack, or grunt

Image
0

1.0K

uconn/local repository overview

⁠Intro

The uconn/local image (available via docker hub) is a flexible docker image for local asset management. Its aim is to create small (160MB), reproducible, containers for task runners. Currently it can be used with:

  • gulp
  • webpack
  • grunt

⁠Usage

The examples below are based on our current docker-compose.yml files. By default when a container is created from this image, it will:

  • create a /project directory as the working directory for the container. This is where all the action is....
  • expose port 3000
  • install dependencies from package.json via yarn and then
  • run the default gulp command.

Examples follow which demonstrate this and other uses.

⁠Default

This is the simplest case. The entire project is mounted to /project inside the container. The container will attempt to run:

  • yarn install
  • gulp (the default task)
local-gulp:
  image: uconn/local:latest
  ports:
    - "3000:3000"
  # mount the entire local project to `/project` in the container
  volumes:
    - ./:/project
  # allow for interactivity
  tty: true

⁠Extending gulp etc...

Sometimes it's desirable to separate watch tasks from the default task. In this case, you can use the same as the above and simply add an entrypoint command. In cases like this it's not necessary to use any additional scripts. The entrypoint command will take each part of the array passed to it as arguments.

entrypoint: ["gulp", "watch"]```

## Using an entrypoint.sh script
This (and the next case) are useful for overriding the default container command. This is useful for passing more complicated commands (or different kinds of commands) to the container. In this case we want to use webpack to run tasks and bundle assets. We pass the watch flag to make sure it stays active. You could use other valid bash commands inside the entrypoint file.
```[docker-compose.yml]

local-webpack:
image: uconn/local:latest
ports:
  - "3000:3000"
volumes:
  - ./:/project
  # mount our entrypoint script (see below)
  - ./.entrypoint/webpack-entrypoint.sh:/project/entrypoint.sh
tty: true
# this will run the script below. 
# it overrides the default entrypoint command
entrypoint: ["bash", "/project/entrypoint.sh"]
---------------
[./entrypoint/webpack-entrypoint.sh]
#!/bin/bash

webpack --watch```

## Using npm as a task runner
I don't know grunt very well, but in this case a grunt task ('log') will be executed via the script.
```[docker-compose.yml]

local-grunt:
image: uconn/local:latest
ports: 
  - "3000:3000"
volumes:
  - ./:/project
tty: true
entrypoint: ["npm", "run", "grunt:log"]
----------------
[./package.json]
{
// other stuff...
"scripts": {
  "grunt:log": "grunt log"
}
}```

## Combining containers
The whole point of using docker-compose is to be able to easily run more than one container at once. If you need to run both gulp and webpack for instance, simply create containers as above (with different names). Then assign them to different ports on the host.
```local-gulp:
ports:
  - "3000:3000"
# other stuff...
local-webpack:
ports:
  - "4000:3000"```

## Container management
Sometimes tasks may throw errors which causes the container to stop. If this is the case simply run 
docker-compose restart {container-name}

## Known issues
- If a project was started before a container made from this image was used, it may be necessary to trash the node_modules directory. If that happens it will be recreated the next time the default image task is run.
- Sometimes docker-compose will error with the message "ERROR: An HTTP request took too long to complete". This may be related to keeping tty open.

Tag summary

Content type

Image

Digest

Size

61.2 MB

Last updated

over 8 years ago

docker pull uconn/local