在Docker容器中更改日期

时间:2020-06-22 17:27:20

标签: docker date

当我在后端创建new Date()时,日期采用UTC±00:00格式。

我需要UTC-3格式。我尝试了诸如thisthis之类的方法,但是没有用。

我输入docker exec -it 68856c74974a date我有:

2020年6月22日星期一6:15:22

我需要:

6月22日星期一14:15:22 -03

$ docker image ls
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
ubuntu                  latest              74435f89ab78        5 days ago          73.9MB
playcode-runner_front   latest              e53bf65cc234        2 weeks ago         1.44GB
playcode-runner_api     latest              be1e67561898        2 weeks ago         186MB
phpmyadmin/phpmyadmin   latest              6f9550cff175        3 weeks ago         469MB
hello-world             latest              bf756fb1ae65        5 months ago        13.3kB
node                    10.14.2             8a752d5af4ce        18 months ago       894MB
mysql                   8.0.3               00400babc1b7        2 years ago         343MB
anapsix/alpine-java     jdk8                ed55c27d366d        3 years ago         171MB

并且:

$ docker image inspect playcode-runner_api

仅一部分:

"Architecture": "amd64",
"Os": "linux",
"Size": 185505062,
"VirtualSize": 185505062,

2 个答案:

答案 0 :(得分:2)

一种可能是从您当前使用的映像中创建自己的Dockerfile,然后添加(as in here):

macro "Change and Resave" {
    dir1 = getDirectory("Choose Source Directory ");
    dir2 = getDirectory("Choose Destination Directory ");
    list = getFileList(dir1);

    // Make an array of files ending " - GFP.vsi"
    nd2list = newArray(0);
    for (i=0; i<list.length; i++) {
        if (endsWith(list[i], " - GFP.vsi")) {
            vsilist = append(vsilist, list[i]);
        }
    }

    setBatchMode(true);
    // loop through files
    for (i=0; i<vsilist.length; i++) {
        showProgress(i+1, vsilist.length);
        // open file using Bio-Formats, you may need to edit these two lines
        s = "open=["+dir1+vsilist[i]+"] autoscale color_mode=Composite rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT";
        run("Bio-Formats Importer", s);
        // your commands from your question
        run("Green");
        run("RGB Color");
        saveAs("tiff", dir2+replace(vsilist[i],".vsi",".tif"));
        close();
    }
    setBatchMode(false);
}

function append(arr, value) {
    arr2 = newArray(arr.length+1);
    for (i=0; i<arr.length; i++)
        arr2[i] = arr[i];
        arr2[arr.length] = value;
    return arr2;
}

然后将使用ISO-8601显示日期,例如:

USER theRightUser
RUN echo "alias date='date -Is'>>~/.bashrc"

答案 1 :(得分:2)

设置TZ变量对我有用:

$ docker run -it --rm -e TZ=UTC ubuntu date -R
Thu, 25 Jun 2020 14:17:30 +0000

$ docker run -it --rm -e TZ=UTC-3 ubuntu date -R
Thu, 25 Jun 2020 17:17:32 +0300

使用docker exec,它可以从启动容器时获取环境,因此您需要使用所需的环境重新创建容器:

$ docker run -d --rm -e TZ=UTC --name utc ubuntu tail -f /dev/null
8abcb471c2fb7c933bbdabd629e0d1d08cd926017ee5f7ccf7d54337d1fd4460

$ docker run -d --rm -e TZ=UTC-3 --name utc-3 ubuntu tail -f /dev/null
670336f127097a1c9f488a086dfd40496be433a7434dd9a3ac38feaaaabbb5db

$ docker exec utc date -R
Fri, 26 Jun 2020 00:08:52 +0000

$ docker exec utc-3 date -R
Fri, 26 Jun 2020 03:08:59 +0300