小编zer*_*oed的帖子

REST API容器创建和端口绑定

我有来自dockerfile的映像,这是设置容器,但我需要使用docker REST API创建和启动容器.问题是我有暴露ssh端口的问题.我已经从dockerfile中删除了EXPOSE,并构建了图像.

之后,我使用这个json在/ containers/create上发出了POST请求:

{"Image":"frantiseks/apac","ExposedPorts":{"22/tcp":{}},"Memory":600000,"CpuShares":50}
Run Code Online (Sandbox Code Playgroud)

Container已成功创建,因此下一步我使用JSON 使用此POST请求 启动它/containers/$id/start:

{"PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }}
Run Code Online (Sandbox Code Playgroud)

但是在检查容器后我没有看到映射端口,所以容器没有暴露22到主机11022端口.我使用的是0.7.1版本.

有人能告诉我我做错了什么吗?谢谢

PS:检查容器:http: //jsonblob.com/52b01e45e4b0439bc58ec8d4

rest json lxc docker

5
推荐指数
1
解决办法
2万
查看次数

如何模拟SecurityContext

泽西岛的终点.

我想用一个端点来保护端点 ContainerRequestFilter

@Provider
@Secured
public class AuthorizationRequestFilter implements ContainerRequestFilter {

    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
        final SecurityContext securityContext =
                requestContext.getSecurityContext();

        //TODO: on logger here...
        System.out.printf("Filtering %s request... AuthorizationRequestFilter\n", requestContext.getMethod());
        requestContext.getHeaders().add("X-Secured-By", "Jersey >_<");
        System.out.printf("SecurityContext: %s (%s).\n", securityContext, securityContext.getAuthenticationScheme());

        if (securityContext == null || !securityContext.isUserInRole("privileged")) {
            requestContext.abortWith(new UnauthorizedResponse().getResponse());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

注释@Secured:

@NameBinding
@Retention(RetentionPolicy.RUNTIME)
public @interface Secured {}
Run Code Online (Sandbox Code Playgroud)

所以我可以这样做:

@Path("foobar")
public class FooResource {

    //...

    @Context
    SecurityContext securityContext;

    //...

    @GET
    @Secured
    @Path(value = "foo")
    @Produces(MediaType.APPLICATION_JSON) …
Run Code Online (Sandbox Code Playgroud)

java unit-testing jax-rs mocking jersey-2.0

5
推荐指数
1
解决办法
6371
查看次数

以数组为键的哈希

我正在定义一个散列,其中数组作为键,另一个数组作为其值.例如:

for_example = {[0,1] => [:a, :b, :c]}
Run Code Online (Sandbox Code Playgroud)

一切都如下所示.

my_hash = Hash.new([])
an_array_as_key = [4,2]
my_hash[an_array_as_key]                #=> []
my_hash[an_array_as_key] << "the"       #=> ["the"]
my_hash[an_array_as_key] << "universal" #=> ["the", "universal"]
my_hash[an_array_as_key] << "answer"    #=> ["the", "universal", "answer"]
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试访问密钥:

my_hash                           #=> {}
my_hash.keys                      #=> []
my_hash.count                     #=> 0
my_hash.values                    #=> []
my_hash.fetch(an_array_as_key)    # KeyError: key not found: [4, 2]
my_hash.has_key?(an_array_as_key) #=> false
Run Code Online (Sandbox Code Playgroud)

Rehash无济于事:

my_hash        #=> {}
my_hash.rehash #=> {}
my_hash.keys   #=> []
Run Code Online (Sandbox Code Playgroud)

但价值得以保存:

my_hash[an_array_as_key] #=> ["the", "universal", "answer"]
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

ruby hash

2
推荐指数
1
解决办法
155
查看次数

标签 统计

docker ×1

hash ×1

java ×1

jax-rs ×1

jersey-2.0 ×1

json ×1

lxc ×1

mocking ×1

rest ×1

ruby ×1

unit-testing ×1