What gulp lib is for build a container and image?

Basically I want to build a container then an image. The image will run in the container just created.
Which gulp library is for that?

I found this one and another one.
Just confused.

I think you mean you want to build an image, then run a container based on that image?

(image == filesystem snapshot. container == running process based on that snapshot).

There’s no official or obvious solution. Many Docker projects frequently have a thin GNU make layer to shell out to Docker, but if you’re adamant about using Gulp for your build tool, my recommendation would be to skip the 3rd party modules you linked (which may, or may not continue to be maintained) and define some tasks around docker-compose (use require('child_process').exec to “shell out” to it).

For instance, this example from the Gulp docs can be modified quite easily to suit your needs.

// run a command in a shell
var exec = require('child_process').exec;
gulp.task('build', function() {
  exec('docker-compose build', function(err) {
    if (err) {
        console.log(err);
    }
  });
});

Hi, thanks for the help. Yes, I want build an image, then run a container based on that image. However at the very beginning, I don’t have the container, thus I have to create a container first.

So I thought the code in gulp.js could likely

var docker = required(“gulp-docker”);
gulp.task(‘run’,[‘run’],function () {
docker([
git: “https://bitbucket.org/test/dockerdemo”,
run: need command here
]);
});

Hmmm… You should create an image and then run a container from it usually, not the other way around.

  1. Create image based on Dockerfile (technically this runs containers, but you don’t run them yourself)
  2. Run container

You could try to access Docker API directly like you seem to want to do above, but I’m pretty convinced that unless what you need to do with Docker is really unique, you’re really likely to end up re-implementing a subset of Docker Compose, and really would be a lot better off just adopting / shelling out to Docker Compose. The vast majority of projects just need to call docker-compose build && docker-compose up -d.

Hi, I am new to docker. Many things to learn. Please forgive my ignorance.:blush:

I followed this [example] (http://www.hanselman.com/blog/PublishingAnASPNET5AppToDockerOnLinuxWithVisualStudio.aspx) to publish an asp.net to the Linux server.

According to the VERBOSE, it seems to find a few intermediate containers and remove them eventually. So does it mean the machine already has containers before the build process? Then how to select the container finally?

No, each line in the Dockerfile does a docker run of the previous line (starting with your base image in FROM – each one of these will create a container) and then docker commit the result, to generate a new image. You could do this by hand, but Dockerfile is much more automatic / documentable and has caching and a few other special tricks. All images are created this way, except for base images which are created from tarball.

The intermediate images are all created in the automatic process as a “snapshot” of each layer. Most of the time you won’t need to worry about these intermediate images.

The image that you spit out, at the end of a docker build, usually gets tagged with -t like so:

$ docker build -t nathanleclaire/apache . 

Then, you can subsequently run it by refering to that name:

$ docker run -d -P nathanleclaire/apache

It seems to me like you are still struggling with understanding the difference between containers and images. I’d suggest getting a feel for the mechanics of how docker build works in practice by baking a few of your own Dockerfiles (e.g. for a very simple Node webapp) before you worry about the “plumbing” of how it works.

Okay, I just found the difference of docker image vs container.If I follow your idea,
var exec = require(‘child_process’).exec;
gulp.task(‘build’, function() {
exec(‘docker-compose build’, function(err) {
if (err) {
console.log(err);
}
});
});

Do I need docker-compose.yml file? I need to place the port information.

Do I need docker-compose.yml file? I need to place the port information.

Yes, you will need Dockerfile (to specify the build) and docker-compose.yml. The official getting started guides, while not specific to Node, are a great reference for the general type of workflow / project structure for Compose: Django samples | Docker Docs

Originally I had the host url tcp://10.50.10.28
Where should I put this information? In docker-compose.yml?

I have not seen the usage.

Depends on what that host URL is exactly. Is that what DOCKER_HOST is meant to point to?

Yes, it is. It is the remote Linux server

Could you give me a sample yml code which has DOCKER_HOST?

Thanks,

You don’t put it in the YAML. You need to set DOCKER_HOST environment variable, either in the shell before invoking Gulp commands, or in the Gulp config using something like this:

process.env['DOCKER_HOST'] = 'tcp://10.50.10.28:2376';