我已经创建了一个项目(非常大的项目,需要花费一些时间来编译)的docker映像,但是我忘记在其中添加文件。
我与构建无关,它只是一个测试文件。
是否可以在不重建所有内容的情况下将此文件添加到我的图像中?
谢谢
答案 0 :(得分:7)
这是一个完整的示例,用于拉取图像、向其中添加本地文件、重新标记图像并将其推回:
public class AppointmentTest {
private final String CLIENT_STRING = "";
@Test
public void shouldAddAppointment() {
AppointmentClientFactory clientFactory = Mockito.mock(AppointmentClientFactory.class);
AppointmentClient mockedClient = Mockito.mock(AppointmentClient.class);
AppointmentService service = new AppointmentService(clientFactory);
Appointment appointmentMock = new Appointment();
when(clientFactory.getUnsecuredClient(any())).thenReturn(mockedClient);
Appointment appointment = service.addAppointment(CLIENT_STRING, appointmentMock);
assertNotNull(appointment);
}
}
答案 1 :(得分:0)
您应该尝试使用docker commit。
示例:docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
也有docker cp,但它仅在运行中的容器中起作用。
我希望这会有所帮助!
布拉卡(Brhaka)
答案 2 :(得分:0)
假定构建正确,并且尚未创建任何容器。我建议您将图像容器化,并通过将其复制到容器中的正确目标位置来手动添加文件。
现在您只需要执行以下步骤:
答案 3 :(得分:0)
是的,请执行以下步骤:
执行命令:
docker cp textFile.txt docker_container_name:/textFile.txt
提交容器以使用新标签版本或其他名称构建新图像;
答案 4 :(得分:0)
ADD 命令用于将文件/目录复制到 Docker 镜像中。它可以通过三种方式复制数据:
1. List item Copy files from the local storage to a destination in the Docker image.
2. Copy a tarball from the local storage and extract it automatically inside a destination in the Docker image.
3. Copy files from a URL to a destination inside the Docker image.
来源:https://www.educative.io/edpresso/what-is-the-docker-add-command