在docker中创建/ tmp目录

时间:2015-11-19 11:22:52

标签: docker dockerfile

我有以下运行node.js应用程序的Docker文件

#!/usr/bin/bash
set -e

TYPE=$1
REPO_URL=https://api.github.com/repos/nkhine/domain/tarball/$2
APP=web-$TYPE
APPENV=/ccc/$APP.env
ls $APPENV > /dev/null
echo using $APPENV

source /ccc/build.env

BUILDID=`date +%Y%m%d.%H%M%S`
BUILDDIR=/ccc/build/$APP-$BUILDID
CACHEDIR=/ccc/build/cache
CACHEFILE=$CACHEDIR/$APP.tar.gz
mkdir -p $BUILDDIR
mkdir -p $CACHEDIR

echo [== downloading $REPO_URL to $BUILDDIR ==]
cd $BUILDDIR
curl -H "Authorization: token $GITHUB_TOKEN" -L $REPO_URL | tar --extract --gzip
cd *

echo [== building docker on `pwd` ==]
IMAGE=$APP:$BUILDID
CONTAINER=$APP
cp $CACHEFILE cache.tar.gz || true
basename `pwd` > git_commit_id

docker build -t $IMAGE .
cd /ccc
rm -Rf $BUILDDIR
docker run --rm $IMAGE cat cache.tar.gz > $CACHEFILE

echo [== restarting docker ==]
docker stop $APP || true
docker rm $APP || true
docker run -d --restart always --name $APP \
    -v /tmp:/ccc/tmp \
    --link euvat:euvat \
    --link freegeoip:freegeoip \
    --link redis-$TYPE:redis \
    --link mongo-$TYPE:mongo \
    --env VIRTUAL_HOST=$TYPE.domain.tld \
    --env-file $APPENV \
    $IMAGE

echo [== tailing docker logs press [Ctrl + C] to cancel ==]
docker logs --tail=100 -f $APP

但当我检查/ccc/tmp时尚未将容器装入/tmp

khine@arawaak ~ $ docker inspect web-dev
[
{
    "Id": "e124e93ca6b92e868ea7fd7fae1ed8a28d3b64302fe72ed771f06c761dedc9cd",
    "Created": "2015-11-19T11:03:41.187310483Z",
    "Path": "node",
    "Args": [
        "run.js"
    ],
    "State": {
        "Running": true,
        "Paused": false,
        "Restarting": false,
        "OOMKilled": false,
        "Dead": false,
        "Pid": 1247,
        "ExitCode": 0,
        "Error": "",
        "StartedAt": "2015-11-19T11:03:41.543628736Z",
        "FinishedAt": "0001-01-01T00:00:00Z"
    },
    "Image": "796201c12ace9547173ea57b38a4e199178bf7fe4e1dfdb686d5029871364411",
    "NetworkSettings": {
        "Bridge": "",
        "NetworkID": "be5690b03359d5214b8a1670e62eb91d618e5a7b2fa3a0fdb1ce3dd27ab21d0a",
        "PortMapping": null,
        "Ports": {
            "3000/tcp": null
        },
        "SandboxKey": "/var/run/docker/netns/e124e93ca6b9",
        "SecondaryIPAddresses": null,
        "SecondaryIPv6Addresses": null
    },
    "ResolvConfPath": "/var/lib/docker/containers/e124e93ca6b92e868ea7fd7fae1ed8a28d3b64302fe72ed771f06c761dedc9cd/resolv.conf",
    "HostnamePath": "/var/lib/docker/containers/e124e93ca6b92e868ea7fd7fae1ed8a28d3b64302fe72ed771f06c761dedc9cd/hostname",
    "HostsPath": "/var/lib/docker/containers/e124e93ca6b92e868ea7fd7fae1ed8a28d3b64302fe72ed771f06c761dedc9cd/hosts",
    "LogPath": "/var/lib/docker/containers/e124e93ca6b92e868ea7fd7fae1ed8a28d3b64302fe72ed771f06c761dedc9cd/e124e93ca6b92e868ea7fd7fae1ed8a28d3b64302fe72ed771f06c761dedc9cd-json.log",
    "Name": "/web-dev",
    "RestartCount": 0,
    "Driver": "overlay",
    "ExecDriver": "native-0.2",
    "MountLabel": "",
    "ProcessLabel": "",
    "Volumes": {},
    "VolumesRW": {},
    "AppArmorProfile": "",
    "ExecIDs": null,
    "HostConfig": {
        "Binds": null,
        "ContainerIDFile": "",
        "LxcConf": [],
        "Memory": 0,
        "MemorySwap": 0,
        "CpuShares": 0,
        "CpuPeriod": 0,
        "CpusetCpus": "",
        "CpusetMems": "",
        "CpuQuota": 0,
        "BlkioWeight": 0,
        "OomKillDisable": false,
        "Privileged": false,
        "PortBindings": {},
        "Links": [
            "/euvat:/web-dev/euvat",
            "/freegeoip:/web-dev/freegeoip",
            "/mongo-dev:/web-dev/mongo",
            "/redis-dev:/web-dev/redis"
        ],
        "PublishAllPorts": false,
        "Dns": null,
        "DnsSearch": null,
        "ExtraHosts": null,
        "VolumesFrom": null,
        "Devices": [],
        "NetworkMode": "bridge",
        "IpcMode": "",
        "PidMode": "",
        "UTSMode": "",
        "CapAdd": null,
        "CapDrop": null,
        "RestartPolicy": {
            "Name": "always",
            "MaximumRetryCount": 0
        },
        "SecurityOpt": null,
        "ReadonlyRootfs": false,
        "Ulimits": null,
        "LogConfig": {
            "Type": "json-file",
            "Config": {}
        },
        "CgroupParent": ""
    },
    "Config": {
        "Hostname": "e124e93ca6b9",
        "Domainname": "",
        "User": "",
        "AttachStdin": false,
        "AttachStdout": false,
        "AttachStderr": false,
        "PortSpecs": null,
        "ExposedPorts": {
            "3000/tcp": {}
        },
        "Tty": false,
        "OpenStdin": false,
        "StdinOnce": false,
        "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "NODE_VERSION=0.10.40",
            "NPM_VERSION=2.13.3",
            "PORT=3000",
            "NODE_ENV=production"
        ],
        "Cmd": [
            "node",
            "run.js"
        ],
        "Image": "web-dev:20151119.110235",
        "Volumes": null,
        "VolumeDriver": "",
        "WorkingDir": "/usr/src/app",
        "Entrypoint": null,
        "NetworkDisabled": false,
        "MacAddress": "",
        "OnBuild": null,
        "Labels": {}
    }
}
]

任何建议非常感谢,我的用例是我使用phantomjs创建一个PDF文件,然后通过电子邮件发送给客户。

1 个答案:

答案 0 :(得分:1)

你有向后的选择。你应该使用:

-v /ccc/tmp:/tmp

Mount a host directory as a data volume